build: update go/parser/resolve.go (compatible go 1.23)

This commit is contained in:
Li Jie
2025-01-10 11:23:47 +08:00
parent e23d7082fe
commit 227f6a4ed7

View File

@@ -136,7 +136,7 @@ func (r *resolver) declare(decl, data any, scope *ast.Scope, kind ast.ObjKind, i
obj.Decl = decl obj.Decl = decl
obj.Data = data obj.Data = data
// Identifiers (for receiver type parameters) are written to the scope, but // Identifiers (for receiver type parameters) are written to the scope, but
// never set as the resolved object. See issue #50956. // never set as the resolved object. See go.dev/issue/50956.
if _, ok := decl.(*ast.Ident); !ok { if _, ok := decl.(*ast.Ident); !ok {
ident.Obj = obj ident.Obj = obj
} }
@@ -209,7 +209,7 @@ func (r *resolver) resolve(ident *ast.Ident, collectUnresolved bool) {
} }
assert(obj.Name != "", "obj with no name") assert(obj.Name != "", "obj with no name")
// Identifiers (for receiver type parameters) are written to the scope, // Identifiers (for receiver type parameters) are written to the scope,
// but never set as the resolved object. See issue #50956. // but never set as the resolved object. See go.dev/issue/50956.
if _, ok := obj.Decl.(*ast.Ident); !ok { if _, ok := obj.Decl.(*ast.Ident); !ok {
ident.Obj = obj ident.Obj = obj
} }
@@ -232,9 +232,19 @@ func (r *resolver) walkExprs(list []ast.Expr) {
} }
} }
func Unparen(e ast.Expr) ast.Expr {
for {
paren, ok := e.(*ast.ParenExpr)
if !ok {
return e
}
e = paren.X
}
}
func (r *resolver) walkLHS(list []ast.Expr) { func (r *resolver) walkLHS(list []ast.Expr) {
for _, expr := range list { for _, expr := range list {
expr := unparen(expr) expr := Unparen(expr)
if _, ok := expr.(*ast.Ident); !ok && expr != nil { if _, ok := expr.(*ast.Ident); !ok && expr != nil {
ast.Walk(r, expr) ast.Walk(r, expr)
} }
@@ -285,7 +295,7 @@ func (r *resolver) Visit(node ast.Node) ast.Visitor {
} }
for _, e := range n.Elts { for _, e := range n.Elts {
if kv, _ := e.(*ast.KeyValueExpr); kv != nil { if kv, _ := e.(*ast.KeyValueExpr); kv != nil {
// See issue #45160: try to resolve composite lit keys, but don't // See go.dev/issue/45160: try to resolve composite lit keys, but don't
// collect them as unresolved if resolution failed. This replicates // collect them as unresolved if resolution failed. This replicates
// existing behavior when resolving during parsing. // existing behavior when resolving during parsing.
if ident, _ := kv.Key.(*ast.Ident); ident != nil { if ident, _ := kv.Key.(*ast.Ident); ident != nil {