aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2022-01-24 14:38:01 -0800
committerDan Scales <danscales@google.com>2022-01-25 00:39:08 +0000
commit16d6a5233a183be7264295c66167d35c689f9372 (patch)
tree3638275208a0dd154db18c223616a59fcae270e7 /src/cmd/compile/internal/noder
parent84eefdc933410907495e42aac872036403851ffa (diff)
downloadgo-16d6a5233a183be7264295c66167d35c689f9372.tar.xz
cmd/compile: new absdiff.go test, fix problem with g.curDecl
Added a new absdiff2.go test case, which works fully without using a typeparam on the right-hand-side of a type declaration (which is disallowed). Fixed an issue that the test revealed, which is that we need to set g.curDecl properly for the "later" functions which are deferred until after all declarations are initially processed. Also, g.curDecl may be non-nil in typeDecl for local type declaration. So, we adjust the associate assertion, and save/restore g.curDecl appropriately. Fixes #50790 Change-Id: Ieed76a7ad0a83bccb99cbad4bf98a7bfafbcbbd3 Reviewed-on: https://go-review.googlesource.com/c/go/+/380594 Reviewed-by: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder')
-rw-r--r--src/cmd/compile/internal/noder/decl.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/noder/decl.go b/src/cmd/compile/internal/noder/decl.go
index df1ca1c505..a9522d09af 100644
--- a/src/cmd/compile/internal/noder/decl.go
+++ b/src/cmd/compile/internal/noder/decl.go
@@ -133,12 +133,20 @@ func (g *irgen) funcDecl(out *ir.Nodes, decl *syntax.FuncDecl) {
g.target.Inits = append(g.target.Inits, fn)
}
- haveEmbed := g.haveEmbed
+ saveHaveEmbed := g.haveEmbed
+ saveCurDecl := g.curDecl
g.curDecl = ""
g.later(func() {
- defer func(b bool) { g.haveEmbed = b }(g.haveEmbed)
+ defer func(b bool, s string) {
+ // Revert haveEmbed and curDecl back to what they were before
+ // the "later" function.
+ g.haveEmbed = b
+ g.curDecl = s
+ }(g.haveEmbed, g.curDecl)
- g.haveEmbed = haveEmbed
+ // Set haveEmbed and curDecl to what they were for this funcDecl.
+ g.haveEmbed = saveHaveEmbed
+ g.curDecl = saveCurDecl
if fn.Type().HasTParam() {
g.topFuncIsGeneric = true
}
@@ -162,9 +170,10 @@ func (g *irgen) funcDecl(out *ir.Nodes, decl *syntax.FuncDecl) {
func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) {
// Set the position for any error messages we might print (e.g. too large types).
base.Pos = g.pos(decl)
- assert(g.curDecl == "")
+ assert(ir.CurFunc != nil || g.curDecl == "")
// Set g.curDecl to the type name, as context for the type params declared
// during types2-to-types1 translation if this is a generic type.
+ saveCurDecl := g.curDecl
g.curDecl = decl.Name.Value
if decl.Alias {
name, _ := g.def(decl.Name)
@@ -225,7 +234,7 @@ func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) {
}
types.ResumeCheckSize()
- g.curDecl = ""
+ g.curDecl = saveCurDecl
if otyp, ok := otyp.(*types2.Named); ok && otyp.NumMethods() != 0 {
methods := make([]*types.Field, otyp.NumMethods())
for i := range methods {