]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix case where g.curDecl should be saved/restored
authorDan Scales <danscales@google.com>
Wed, 1 Dec 2021 18:53:17 +0000 (10:53 -0800)
committerDan Scales <danscales@google.com>
Thu, 2 Dec 2021 07:04:05 +0000 (07:04 +0000)
commitd34051bf16d86a88e6c5764aa076219069702045
treea80556f2aca78d003a804a084423e578e8c26671
parent1b2930d70c8bad5ecae08275e56e228e0f424b02
cmd/compile: fix case where g.curDecl should be saved/restored

When we set g.curDecl for the type params created during fillinMethods
for an instantiated type, we need to save/restore its value, because
fillinMethods() may be called while processing a typeDecl. We want the
value of g.curDecl to continue to be correct for type params created in
the typeDecl. Because of ordering issues, not restoring g.curDecl
happens to cause problems (which don't always show up visibly) exactly
when a type param is not actually used in a type declaration.

Cleared g.curDecl to "" at the later points in typeDecl() and
funcDecl(). This allows adding asserts that g.curDecl is always empty
("") when we set it in typeDecl() and funcDecl(), and always non-empty
when we use it in typ0().

Fixes #49893

Change-Id: Ic2fb1df791585bd257f2b86ffaae0453c31705c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/368454
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/noder/decl.go
src/cmd/compile/internal/noder/types.go
test/typeparam/issue49893.dir/a.go [new file with mode: 0644]
test/typeparam/issue49893.dir/b.go [new file with mode: 0644]
test/typeparam/issue49893.dir/main.go [new file with mode: 0644]
test/typeparam/issue49893.go [new file with mode: 0644]