go/types, types2: fix object path for grouped declaration statements

CL 715840 deferred popping from the object path during handling of
grouped declaration statements, which leaves extra objects on the
path since this executes in a loop.

Surprisingly, no test exercised this. This change fixes this small
bug and adds a supporting test.

Fixes #76366

Change-Id: I7fc038b39d3871eea3e60855c46614b463bcfa4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/722060
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Mark Freeman 2025-11-19 15:10:24 -05:00 committed by Gopher Robot
parent 33529db142
commit 4fef9f8b55
3 changed files with 14 additions and 2 deletions

View file

@ -876,8 +876,8 @@ func (check *Checker) declStmt(list []syntax.Decl) {
scopePos := s.Name.Pos() scopePos := s.Name.Pos()
check.declare(check.scope, s.Name, obj, scopePos) check.declare(check.scope, s.Name, obj, scopePos)
check.push(obj) // mark as grey check.push(obj) // mark as grey
defer check.pop()
check.typeDecl(obj, s, nil) check.typeDecl(obj, s, nil)
check.pop()
default: default:
check.errorf(s, InvalidSyntaxTree, "unknown syntax.Decl node %T", s) check.errorf(s, InvalidSyntaxTree, "unknown syntax.Decl node %T", s)

View file

@ -935,8 +935,8 @@ func (check *Checker) declStmt(d ast.Decl) {
scopePos := d.spec.Name.Pos() scopePos := d.spec.Name.Pos()
check.declare(check.scope, d.spec.Name, obj, scopePos) check.declare(check.scope, d.spec.Name, obj, scopePos)
check.push(obj) // mark as grey check.push(obj) // mark as grey
defer check.pop()
check.typeDecl(obj, d.spec, nil) check.typeDecl(obj, d.spec, nil)
check.pop()
default: default:
check.errorf(d.node(), InvalidSyntaxTree, "unknown ast.Decl node %T", d.node()) check.errorf(d.node(), InvalidSyntaxTree, "unknown ast.Decl node %T", d.node())
} }

View file

@ -0,0 +1,12 @@
// Copyright 2025 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package p
func _() {
type (
A = int
B = []A
)
}