From 06478e4b4659966e4f5dba1f399da9767995fee5 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 25 Apr 2024 08:57:36 -0700 Subject: go/types, types2: simplify Default function Change-Id: Ie2b7c1324ec7947c6ff43187dda99b83bcb64f08 Reviewed-on: https://go-review.googlesource.com/c/go/+/581775 Reviewed-by: Robert Findley Reviewed-by: Robert Griesemer Auto-Submit: Robert Griesemer LUCI-TryBot-Result: Go LUCI --- src/cmd/compile/internal/types2/predicates.go | 4 +++- src/go/types/predicates.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/types2/predicates.go b/src/cmd/compile/internal/types2/predicates.go index 6d9e6ec760..986cd6aa61 100644 --- a/src/cmd/compile/internal/types2/predicates.go +++ b/src/cmd/compile/internal/types2/predicates.go @@ -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] diff --git a/src/go/types/predicates.go b/src/go/types/predicates.go index 1889694342..83bc64772f 100644 --- a/src/go/types/predicates.go +++ b/src/go/types/predicates.go @@ -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] -- cgit v1.2.3-54-g00ecf