]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: document why Unalias is not needed in some places
authorRobert Griesemer <gri@golang.org>
Thu, 23 May 2024 21:40:22 +0000 (14:40 -0700)
committerRobert Griesemer <gri@google.com>
Thu, 23 May 2024 23:17:08 +0000 (23:17 +0000)
Documentation change only.

For #67547.

Change-Id: I0da480299c33239bcd1e059f8b9c6d48d8f26609
Reviewed-on: https://go-review.googlesource.com/c/go/+/587820
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

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

index 1cdc4e79a2a0c7288b03d14605f2cafd07451b04..2a46de9b9742e1c7c6c3a0b0375a19731c966803 100644 (file)
@@ -184,6 +184,10 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
                                // Thus, for untyped arguments we only need to look at parameter types
                                // that are single type parameters.
                                // Also, untyped nils don't have a default type and can be ignored.
+                               // Finally, it's not possible to have an alias type denoting a type
+                               // parameter declared by the current function and use it in the same
+                               // function signature; hence we don't need to Unalias before the
+                               // .(*TypeParam) type assertion above.
                                untyped = append(untyped, i)
                        }
                }
@@ -306,7 +310,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
        // maximum untyped type for each of those parameters, if possible.
        var maxUntyped map[*TypeParam]Type // lazily allocated (we may not need it)
        for _, index := range untyped {
-               tpar := params.At(index).typ.(*TypeParam) // is type parameter by construction of untyped
+               tpar := params.At(index).typ.(*TypeParam) // is type parameter (no alias) by construction of untyped
                if u.at(tpar) == nil {
                        arg := args[index] // arg corresponding to tpar
                        if maxUntyped == nil {
index 76c3c72a1a326b753b57b487bdcf05e3680fc477..7e63b0a6653f599763a606bb9142f9cc1d49da8a 100644 (file)
@@ -187,6 +187,10 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
                                // Thus, for untyped arguments we only need to look at parameter types
                                // that are single type parameters.
                                // Also, untyped nils don't have a default type and can be ignored.
+                               // Finally, it's not possible to have an alias type denoting a type
+                               // parameter declared by the current function and use it in the same
+                               // function signature; hence we don't need to Unalias before the
+                               // .(*TypeParam) type assertion above.
                                untyped = append(untyped, i)
                        }
                }
@@ -309,7 +313,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
        // maximum untyped type for each of those parameters, if possible.
        var maxUntyped map[*TypeParam]Type // lazily allocated (we may not need it)
        for _, index := range untyped {
-               tpar := params.At(index).typ.(*TypeParam) // is type parameter by construction of untyped
+               tpar := params.At(index).typ.(*TypeParam) // is type parameter (no alias) by construction of untyped
                if u.at(tpar) == nil {
                        arg := args[index] // arg corresponding to tpar
                        if maxUntyped == nil {