diff options
Diffstat (limited to 'src/cmd/compile/internal/types2/typexpr.go')
-rw-r--r-- | src/cmd/compile/internal/types2/typexpr.go | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go index b758c0f358..02f9b2804d 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -138,11 +138,11 @@ func (check *Checker) varType(e syntax.Expr) Type { // ordinaryType reports an error if typ is an interface type containing // type lists or is (or embeds) the predeclared type comparable. func (check *Checker) ordinaryType(pos syntax.Pos, typ Type) { - // We don't want to call Under() (via Interface) or complete interfaces while we + // We don't want to call under() (via Interface) or complete interfaces while we // are in the middle of type-checking parameter declarations that might belong to // interface methods. Delay this check to the end of type-checking. check.atEnd(func() { - if t := typ.Interface(); t != nil { + if t := asInterface(typ); t != nil { check.completeInterface(pos, t) // TODO(gri) is this the correct position? if t.allTypes != nil { check.softErrorf(pos, "interface contains type constraints (%s)", t.allTypes) @@ -302,7 +302,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams [] // Also: Don't report an error via genericType since it will be reported // again when we type-check the signature. // TODO(gri) maybe the receiver should be marked as invalid instead? - if recv := check.genericType(rname, false).Named(); recv != nil { + if recv := asNamed(check.genericType(rname, false)); recv != nil { recvTParams = recv.tparams } } @@ -382,7 +382,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams [] // (ignore invalid types - error was reported before) if t := rtyp; t != Typ[Invalid] { var err string - if T := t.Named(); T != nil { + if T := asNamed(t); T != nil { // spec: "The type denoted by T is called the receiver base type; it must not // be a pointer or interface type and it must be declared in the same package // as the method." @@ -393,7 +393,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams [] err = "" } } else { - switch u := optype(T.Under()).(type) { + switch u := optype(T).(type) { case *Basic: // unsafe.Pointer is treated like a regular pointer if u.kind == UnsafePointer { @@ -403,7 +403,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams [] err = "pointer or interface type" } } - } else if T := t.Basic(); T != nil { + } else if T := asBasic(t); T != nil { err = "basic or unnamed type" if check.conf.CompilerErrorMessages { check.errorf(recv.pos, "cannot define new methods on non-local type %s", recv.typ) @@ -426,7 +426,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams [] } // goTypeName returns the Go type name for typ and -// removes any occurences of "types." from that name. +// removes any occurrences of "types." from that name. func goTypeName(typ Type) string { return strings.Replace(fmt.Sprintf("%T", typ), "types.", "", -1) // strings.ReplaceAll is not available in Go 1.4 } @@ -442,7 +442,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) { check.indent-- var under Type if T != nil { - // Calling Under() here may lead to endless instantiations. + // Calling under() here may lead to endless instantiations. // Test case: type T[P any] *T[P] // TODO(gri) investigate if that's a bug or to be expected // (see also analogous comment in Checker.instantiate). @@ -575,7 +575,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) { check.atEnd(func() { if !Comparable(typ.key) { var why string - if typ.key.TypeParam() != nil { + if asTypeParam(typ.key) != nil { why = " (missing comparable constraint)" } check.errorf(e.Key, "invalid map key type %s%s", typ.key, why) @@ -644,7 +644,7 @@ func (check *Checker) instantiatedType(x syntax.Expr, targs []syntax.Expr, def * if b == Typ[Invalid] { return b // error already reported } - base := b.Named() + base := asNamed(b) if base == nil { unreachable() // should have been caught by genericType } @@ -710,7 +710,7 @@ func (check *Checker) arrayLength(e syntax.Expr) int64 { } // typeList provides the list of types corresponding to the incoming expression list. -// If an error occured, the result is nil, but all list elements were type-checked. +// If an error occurred, the result is nil, but all list elements were type-checked. func (check *Checker) typeList(list []syntax.Expr) []Type { res := make([]Type, len(list)) // res != nil even if len(list) == 0 for i, x := range list { @@ -943,9 +943,13 @@ func (check *Checker) completeInterface(pos syntax.Pos, ityp *Interface) { check.errorf(pos, "duplicate method %s", m.name) check.errorf(mpos[other.(*Func)], "\tother declaration of %s", m.name) // secondary error, \t indented default: - // check method signatures after all types are computed (issue #33656) + // We have a duplicate method name in an embedded (not explicitly declared) method. + // Check method signatures after all types are computed (issue #33656). + // If we're pre-go1.14 (overlapping embeddings are not permitted), report that + // error here as well (even though we could do it eagerly) because it's the same + // error message. check.atEnd(func() { - if !check.identical(m.typ, other.Type()) { + if !check.allowVersion(m.pkg, 1, 14) || !check.identical(m.typ, other.Type()) { check.errorf(pos, "duplicate method %s", m.name) check.errorf(mpos[other.(*Func)], "\tother declaration of %s", m.name) // secondary error, \t indented } @@ -963,8 +967,8 @@ func (check *Checker) completeInterface(pos syntax.Pos, ityp *Interface) { posList := check.posMap[ityp] for i, typ := range ityp.embeddeds { pos := posList[i] // embedding position - utyp := typ.Under() - etyp := utyp.Interface() + utyp := under(typ) + etyp := asInterface(utyp) if etyp == nil { if utyp != Typ[Invalid] { var format string @@ -1041,7 +1045,7 @@ func (a byUniqueTypeName) Less(i, j int) bool { return sortName(a[i]) < sortName func (a byUniqueTypeName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func sortName(t Type) string { - if named := t.Named(); named != nil { + if named := asNamed(t); named != nil { return named.obj.Id() } return "" @@ -1155,12 +1159,12 @@ func (check *Checker) structType(styp *Struct, e *syntax.StructType) { // Because we have a name, typ must be of the form T or *T, where T is the name // of a (named or alias) type, and t (= deref(typ)) must be the type of T. // We must delay this check to the end because we don't want to instantiate - // (via t.Under()) a possibly incomplete type. + // (via under(t)) a possibly incomplete type. embeddedTyp := typ // for closure below embeddedPos := pos check.atEnd(func() { t, isPtr := deref(embeddedTyp) - switch t := optype(t.Under()).(type) { + switch t := optype(t).(type) { case *Basic: if t == Typ[Invalid] { // error was reported before @@ -1200,8 +1204,6 @@ func embeddedFieldIdent(e syntax.Expr) *syntax.Name { return e.Sel case *syntax.IndexExpr: return embeddedFieldIdent(e.X) - case *syntax.ParenExpr: - return embeddedFieldIdent(e.X) } return nil // invalid embedded field } @@ -1222,7 +1224,7 @@ func (check *Checker) collectTypeConstraints(pos syntax.Pos, types []syntax.Expr // Note: This is a quadratic algorithm, but type lists tend to be short. check.atEnd(func() { for i, t := range list { - if t := t.Interface(); t != nil { + if t := asInterface(t); t != nil { check.completeInterface(types[i].Pos(), t) } if includes(list[:i], t) { |