]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: add missing Unalias calls (clarification)
authorRobert Griesemer <gri@golang.org>
Tue, 21 May 2024 21:35:14 +0000 (14:35 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 21 May 2024 22:01:56 +0000 (22:01 +0000)
This change adds an Unalias call in applyTypeFunc and arrayPtrDeref.
At the moment this doesn't change anything or fix any bugs because
of the way these two functions are invoked, but that could change
in the future.

Also, manually reviewed all type assertions to Type types.

Excluding assertions to type parameters, no obvious issues
were found except for #67540 for which a separate fix is pending.

There are potential issues with assertions type parameters
which will be addressed in a follow-up CL.

For #67547.

Change-Id: I312268dc5e104f95b68f115f00aec3ec4c82e41f
Reviewed-on: https://go-review.googlesource.com/c/go/+/587156
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/types2/builtins.go
src/go/types/builtins.go

index b897a55212b917a3da9d8044dce44df36e2891c4..8b08e498f3e70bfc5e216833503c1eb56943bb04 100644 (file)
@@ -960,7 +960,7 @@ func hasVarSize(t Type, seen map[*Named]bool) (varSized bool) {
 // applyTypeFunc returns nil.
 // If x is not a type parameter, the result is f(x).
 func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId) Type {
-       if tp, _ := x.typ.(*TypeParam); tp != nil {
+       if tp, _ := Unalias(x.typ).(*TypeParam); tp != nil {
                // Test if t satisfies the requirements for the argument
                // type and collect possible result types at the same time.
                var terms []*Term
@@ -1026,7 +1026,7 @@ func makeSig(res Type, args ...Type) *Signature {
 // arrayPtrDeref returns A if typ is of the form *A and A is an array;
 // otherwise it returns typ.
 func arrayPtrDeref(typ Type) Type {
-       if p, ok := typ.(*Pointer); ok {
+       if p, ok := Unalias(typ).(*Pointer); ok {
                if a, _ := under(p.base).(*Array); a != nil {
                        return a
                }
index 43a87498aef51b01d9bb63c035f89d520503fbad..b8963f32481b0580a8926ddcac91822b263937e5 100644 (file)
@@ -963,7 +963,7 @@ func hasVarSize(t Type, seen map[*Named]bool) (varSized bool) {
 // applyTypeFunc returns nil.
 // If x is not a type parameter, the result is f(x).
 func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId) Type {
-       if tp, _ := x.typ.(*TypeParam); tp != nil {
+       if tp, _ := Unalias(x.typ).(*TypeParam); tp != nil {
                // Test if t satisfies the requirements for the argument
                // type and collect possible result types at the same time.
                var terms []*Term
@@ -1029,7 +1029,7 @@ func makeSig(res Type, args ...Type) *Signature {
 // arrayPtrDeref returns A if typ is of the form *A and A is an array;
 // otherwise it returns typ.
 func arrayPtrDeref(typ Type) Type {
-       if p, ok := typ.(*Pointer); ok {
+       if p, ok := Unalias(typ).(*Pointer); ok {
                if a, _ := under(p.base).(*Array); a != nil {
                        return a
                }