aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/decl.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-02-17 17:56:34 -0800
committerRobert Griesemer <gri@golang.org>2021-02-18 20:47:17 +0000
commit099374b55e8aed17d1e77a1084f8fb78ff2f8162 (patch)
treea93d6b9f5cd0c51a25b3072cddba372c85c850c0 /src/cmd/compile/internal/types2/decl.go
parent653386a89a702b54bb01be893cfd30cddb0e6107 (diff)
downloadgo-099374b55e8aed17d1e77a1084f8fb78ff2f8162.tar.gz
go-099374b55e8aed17d1e77a1084f8fb78ff2f8162.zip
[dev.typeparams] cmd/compile/internal/types2: remove Type.Under method in favor of function
This removes the need for the aType embedded type and brings the types2.Type API in sync with the go/types.Type API. For reasons not fully understood yet, introducing the new under function causes a very long initialization cycle error, which doesn't exist in go/types. For now, circumvent the problem through a helper function variable. This CL also eliminates superflous (former) Under() method calls inside optype calls (optype takes care of this). Plus some minor misc. cleanups and comment adjustments. Change-Id: I86e13ccf6f0b34d7496240ace61a1c84856b6033 Reviewed-on: https://go-review.googlesource.com/c/go/+/293470 Reviewed-by: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types2/decl.go')
-rw-r--r--src/cmd/compile/internal/types2/decl.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go
index e9fc08df37..677172d40f 100644
--- a/src/cmd/compile/internal/types2/decl.go
+++ b/src/cmd/compile/internal/types2/decl.go
@@ -445,7 +445,7 @@ func (check *Checker) constDecl(obj *Const, typ, init syntax.Expr, inherited boo
if !isConstType(t) {
// don't report an error if the type is an invalid C (defined) type
// (issue #22090)
- if t.Under() != Typ[Invalid] {
+ if under(t) != Typ[Invalid] {
check.errorf(typ, "invalid constant type %s", t)
}
obj.typ = Typ[Invalid]
@@ -545,13 +545,13 @@ func (check *Checker) varDecl(obj *Var, lhs []*Var, typ, init syntax.Expr) {
check.initVars(lhs, []syntax.Expr{init}, nopos)
}
-// Under returns the expanded underlying type of n0; possibly by following
+// under returns the expanded underlying type of n0; possibly by following
// forward chains of named types. If an underlying type is found, resolve
// the chain by setting the underlying type for each defined type in the
// chain before returning it. If no underlying type is found or a cycle
// is detected, the result is Typ[Invalid]. If a cycle is detected and
// n0.check != nil, the cycle is reported.
-func (n0 *Named) Under() Type {
+func (n0 *Named) under() Type {
u := n0.underlying
if u == nil {
return Typ[Invalid]
@@ -584,6 +584,8 @@ func (n0 *Named) Under() Type {
if i, ok := seen[n]; ok {
// cycle
+ // TODO(gri) revert this to a method on Checker. Having a possibly
+ // nil Checker on Named and TypeParam is too subtle.
if n0.check != nil {
n0.check.cycleError(path[i:])
}
@@ -667,7 +669,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named
// any forward chain.
// TODO(gri) Investigate if we can just use named.origin here
// and rely on lazy computation of the underlying type.
- named.underlying = named.Under()
+ named.underlying = under(named)
}
}
@@ -716,7 +718,7 @@ func (check *Checker) collectTypeParams(list []*syntax.Field) (tparams []*TypeNa
// we may not have a complete interface yet:
// type C(type T C) interface {}
// (issue #39724).
- if _, ok := bound.Under().(*Interface); ok {
+ if _, ok := under(bound).(*Interface); ok {
// set the type bounds
for i < j {
tparams[i].typ.(*TypeParam).bound = bound