]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: simplify Default function
authorRobert Griesemer <gri@golang.org>
Thu, 25 Apr 2024 15:57:36 +0000 (08:57 -0700)
committerRobert Griesemer <gri@google.com>
Thu, 25 Apr 2024 17:07:36 +0000 (17:07 +0000)
Change-Id: Ie2b7c1324ec7947c6ff43187dda99b83bcb64f08
Reviewed-on: https://go-review.googlesource.com/c/go/+/581775
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

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

index 6d9e6ec760da1f5f87b985130a214d7e6e35f0bf..986cd6aa61be78dc114813ee683260d4b4f02507 100644 (file)
@@ -518,7 +518,9 @@ func identicalInstance(xorig Type, xargs []Type, yorig Type, yargs []Type) bool
 // it returns the incoming type for all other types. The default type
 // for untyped nil is untyped nil.
 func Default(t Type) Type {
-       if t, ok := Unalias(t).(*Basic); ok {
+       // Alias and named types cannot denote untyped types
+       // so there's no need to call Unalias or under, below.
+       if t, _ := t.(*Basic); t != nil {
                switch t.kind {
                case UntypedBool:
                        return Typ[Bool]
index 1889694342821d2f66a21682c66fee7c0eeefbed..83bc64772fb630510009b95a278871d78de27906 100644 (file)
@@ -521,7 +521,9 @@ func identicalInstance(xorig Type, xargs []Type, yorig Type, yargs []Type) bool
 // it returns the incoming type for all other types. The default type
 // for untyped nil is untyped nil.
 func Default(t Type) Type {
-       if t, ok := Unalias(t).(*Basic); ok {
+       // Alias and named types cannot denote untyped types
+       // so there's no need to call Unalias or under, below.
+       if t, _ := t.(*Basic); t != nil {
                switch t.kind {
                case UntypedBool:
                        return Typ[Bool]