]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove coreType call in lookup
authorRobert Griesemer <gri@golang.org>
Mon, 24 Feb 2025 23:00:55 +0000 (15:00 -0800)
committerRobert Griesemer <gri@google.com>
Tue, 25 Feb 2025 16:17:21 +0000 (08:17 -0800)
For #70128.

Change-Id: I7d16ad7fdc6b07a2632b4eaefaedfa2bcceffe1d
Reviewed-on: https://go-review.googlesource.com/c/go/+/652215
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

src/cmd/compile/internal/types2/lookup.go
src/go/types/lookup.go

index b8d120f154cd9920839a68c922c2e50cd885d2c8..8f87dc096109304d8d4682d4585a073217e57fd9 100644 (file)
@@ -67,13 +67,13 @@ func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string, fo
 
        obj, index, indirect = lookupFieldOrMethodImpl(T, addressable, pkg, name, foldCase)
 
-       // If we didn't find anything and if we have a type parameter with a core type,
-       // see if there is a matching field (but not a method, those need to be declared
-       // explicitly in the constraint). If the constraint is a named pointer type (see
-       // above), we are ok here because only fields are accepted as results.
+       // If we didn't find anything and if we have a type parameter with a shared underlying
+       // type, see if there is a matching field (but not a method, those need to be declared
+       // explicitly in the constraint). If the constraint is a named pointer type (see above),
+       // we are ok here because only fields are accepted as results.
        const enableTParamFieldLookup = false // see go.dev/issue/51576
        if enableTParamFieldLookup && obj == nil && isTypeParam(T) {
-               if t := coreType(T); t != nil {
+               if t := sharedUnder(nil, T, nil); t != nil {
                        obj, index, indirect = lookupFieldOrMethodImpl(t, addressable, pkg, name, foldCase)
                        if _, ok := obj.(*Var); !ok {
                                obj, index, indirect = nil, nil, false // accept fields (variables) only
index 6c95a9c8d7e8d27f6988c9922812aed131099278..cbf16ae7c80f68283ea0645584c3a86325c99039 100644 (file)
@@ -70,13 +70,13 @@ func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string, fo
 
        obj, index, indirect = lookupFieldOrMethodImpl(T, addressable, pkg, name, foldCase)
 
-       // If we didn't find anything and if we have a type parameter with a core type,
-       // see if there is a matching field (but not a method, those need to be declared
-       // explicitly in the constraint). If the constraint is a named pointer type (see
-       // above), we are ok here because only fields are accepted as results.
+       // If we didn't find anything and if we have a type parameter with a shared underlying
+       // type, see if there is a matching field (but not a method, those need to be declared
+       // explicitly in the constraint). If the constraint is a named pointer type (see above),
+       // we are ok here because only fields are accepted as results.
        const enableTParamFieldLookup = false // see go.dev/issue/51576
        if enableTParamFieldLookup && obj == nil && isTypeParam(T) {
-               if t := coreType(T); t != nil {
+               if t := sharedUnder(nil, T, nil); t != nil {
                        obj, index, indirect = lookupFieldOrMethodImpl(t, addressable, pkg, name, foldCase)
                        if _, ok := obj.(*Var); !ok {
                                obj, index, indirect = nil, nil, false // accept fields (variables) only