aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types/scope.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2018-06-21 16:12:17 -0700
committerMatthew Dempsky <mdempsky@google.com>2018-06-22 17:57:09 +0000
commitf422bea498b138022135060050bbbc249589a945 (patch)
treee481dc22c1a098f22c76642054bb18f800bbca40 /src/cmd/compile/internal/types/scope.go
parent78a579316b84f68eaf8ee401e77fdb85bb13483f (diff)
downloadgo-f422bea498b138022135060050bbbc249589a945.tar.gz
go-f422bea498b138022135060050bbbc249589a945.zip
cmd/compile: fix compile failure for lazily resolved shadowed types
If expanding an inline function body required lazily expanding a package-scoped type whose identifier was shadowed within the function body, the lazy expansion would instead overwrite the local symbol definition instead of the package-scoped symbol. This was due to importsym using s.Def instead of s.PkgDef. Unfortunately, this is yet another consequence of the current awkward scope handling code. Passes toolstash-check. Fixes #25984. Change-Id: Ia7033e1749a883e6e979c854d4b12b0b28083dd8 Reviewed-on: https://go-review.googlesource.com/120456 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types/scope.go')
-rw-r--r--src/cmd/compile/internal/types/scope.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/types/scope.go b/src/cmd/compile/internal/types/scope.go
index 156174746f..40d3d86ef1 100644
--- a/src/cmd/compile/internal/types/scope.go
+++ b/src/cmd/compile/internal/types/scope.go
@@ -80,15 +80,24 @@ func IsDclstackValid() bool {
// PkgDef returns the definition associated with s at package scope.
func (s *Sym) PkgDef() *Node {
+ return *s.pkgDefPtr()
+}
+
+// SetPkgDef sets the definition associated with s at package scope.
+func (s *Sym) SetPkgDef(n *Node) {
+ *s.pkgDefPtr() = n
+}
+
+func (s *Sym) pkgDefPtr() **Node {
// Look for outermost saved declaration, which must be the
// package scope definition, if present.
for _, d := range dclstack {
if s == d.sym {
- return d.def
+ return &d.def
}
}
// Otherwise, the declaration hasn't been shadowed within a
// function scope.
- return s.Def
+ return &s.Def
}