Revert "go/types, types2: don't register interface methods in Info.Types map"

This reverts commit 4ac729283c.

Reason for revert: changes semantics of types.Info.TypeOf; introduces new inconsistency around FieldList types.

For #74303

Change-Id: Ib99558c95f1b615fa9a02b028500ed230c8bb185
Reviewed-on: https://go-review.googlesource.com/c/go/+/683297
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Robert Findley 2025-06-23 07:04:06 -07:00 committed by Gopher Robot
parent 49cdf0c42e
commit 1cf6386b5e
2 changed files with 16 additions and 20 deletions

View file

@ -137,19 +137,17 @@ func (check *Checker) interfaceType(ityp *Interface, iface *syntax.InterfaceType
name := f.Name.Value name := f.Name.Value
if name == "_" { if name == "_" {
check.error(f.Name, BlankIfaceMethod, "methods must have a unique non-blank name") check.error(f.Name, BlankIfaceMethod, "methods must have a unique non-blank name")
continue // ignore method continue // ignore
} }
// Type-check method declaration. typ := check.typ(f.Type)
// Note: Don't call check.typ(f.Type) as that would record sig, _ := typ.(*Signature)
// the method incorrectly as a type expression in Info.Types. if sig == nil {
ftyp, _ := f.Type.(*syntax.FuncType) if isValid(typ) {
if ftyp == nil { check.errorf(f.Type, InvalidSyntaxTree, "%s is not a method signature", typ)
check.errorf(f.Type, InvalidSyntaxTree, "%s is not a method signature", f.Type) }
continue // ignore method continue // ignore
} }
sig := new(Signature)
check.funcType(sig, nil, nil, ftyp)
// use named receiver type if available (for better error messages) // use named receiver type if available (for better error messages)
var recvTyp Type = ityp var recvTyp Type = ityp

View file

@ -176,19 +176,17 @@ func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, d
name := f.Names[0] name := f.Names[0]
if name.Name == "_" { if name.Name == "_" {
check.error(name, BlankIfaceMethod, "methods must have a unique non-blank name") check.error(name, BlankIfaceMethod, "methods must have a unique non-blank name")
continue // ignore method continue // ignore
} }
// Type-check method declaration. typ := check.typ(f.Type)
// Note: Don't call check.typ(f.Type) as that would record sig, _ := typ.(*Signature)
// the method incorrectly as a type expression in Info.Types. if sig == nil {
ftyp, _ := f.Type.(*ast.FuncType) if isValid(typ) {
if ftyp == nil { check.errorf(f.Type, InvalidSyntaxTree, "%s is not a method signature", typ)
check.errorf(f.Type, InvalidSyntaxTree, "%s is not a method signature", f.Type) }
continue // ignore method continue // ignore
} }
sig := new(Signature)
check.funcType(sig, nil, ftyp)
// The go/parser doesn't accept method type parameters but an ast.FuncType may have them. // The go/parser doesn't accept method type parameters but an ast.FuncType may have them.
if sig.tparams != nil { if sig.tparams != nil {