diff options
Diffstat (limited to 'src/cmd/compile/internal/types2/decl.go')
-rw-r--r-- | src/cmd/compile/internal/types2/decl.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go index 0b7956f287..f0a037adb0 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] @@ -559,7 +559,7 @@ func (n0 *Named) Under() Type { // If the underlying type of a defined type is not a defined // type, then that is the desired underlying type. - n := u.Named() + n := asNamed(u) if n == nil { return u // common case } @@ -573,7 +573,7 @@ func (n0 *Named) Under() Type { u = Typ[Invalid] break } - n1 := u.Named() + n1 := asNamed(u) if n1 == nil { break // end of chain } @@ -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:]) } @@ -629,6 +631,9 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named if alias { // type alias declaration + if !check.allowVersion(obj.pkg, 1, 9) { + check.errorf(tdecl, "type aliases requires go1.9 or later") + } obj.typ = Typ[Invalid] obj.typ = check.anyType(tdecl.Type) @@ -664,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) } } @@ -702,7 +707,7 @@ func (check *Checker) collectTypeParams(list []*syntax.Field) (tparams []*TypeNa // The predeclared identifier "any" is visible only as a constraint // in a type parameter list. Look for it before general constraint // resolution. - if tident, _ := f.Type.(*syntax.Name); tident != nil && tident.Value == "any" && check.lookup("any") == nil { + if tident, _ := unparen(f.Type).(*syntax.Name); tident != nil && tident.Value == "any" && check.lookup("any") == nil { bound = universeAny } else { bound = check.typ(f.Type) @@ -713,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 @@ -757,7 +762,7 @@ func (check *Checker) collectMethods(obj *TypeName) { // spec: "If the base type is a struct type, the non-blank method // and field names must be distinct." - base := obj.typ.Named() // shouldn't fail but be conservative + base := asNamed(obj.typ) // shouldn't fail but be conservative if base != nil { if t, _ := base.underlying.(*Struct); t != nil { for _, fld := range t.fields { |