]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/compile/internal/types2/signature.go
go/types, types2: introduce _Alias type node
[gostls13.git] / src / cmd / compile / internal / types2 / signature.go
index 47454a3adffd92b4b4ab7dfc12799038241fd848..f876b16c8f6b4c47a3c0195b0a80d32c7e5084c3 100644 (file)
@@ -7,6 +7,7 @@ package types2
 import (
        "cmd/compile/internal/syntax"
        "fmt"
+       . "internal/types/errors"
 )
 
 // ----------------------------------------------------------------------------
@@ -135,7 +136,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, nil).(*Named); recv != nil {
+                               if recv := asNamed(check.genericType(rname, nil)); recv != nil {
                                        recvTParams = recv.TypeParams().list()
                                }
                        }
@@ -153,10 +154,10 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
                        } else if len(tparams) < len(recvTParams) {
                                // Reporting an error here is a stop-gap measure to avoid crashes in the
                                // compiler when a type parameter/argument cannot be inferred later. It
-                               // may lead to follow-on errors (see issues #51339, #51343).
+                               // may lead to follow-on errors (see issues go.dev/issue/51339, go.dev/issue/51343).
                                // TODO(gri) find a better solution
                                got := measure(len(tparams), "type parameter")
-                               check.errorf(recvPar, _BadRecv, "got %s, but receiver base type declares %d", got, len(recvTParams))
+                               check.errorf(recvPar, BadRecv, "got %s, but receiver base type declares %d", got, len(recvTParams))
                        }
                }
        }
@@ -178,7 +179,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
        results, _ := check.collectParams(scope, ftyp.ResultList, false)
        scope.Squash(func(obj, alt Object) {
                var err error_
-               err.code = _DuplicateDecl
+               err.code = DuplicateDecl
                err.errorf(obj, "%s redeclared in this block", obj.Name())
                err.recordAltDecl(alt)
                check.report(&err)
@@ -195,7 +196,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
                        recv = NewParam(nopos, nil, "", Typ[Invalid]) // ignore recv below
                default:
                        // more than one receiver
-                       check.error(recvList[len(recvList)-1].Pos(), _InvalidRecv, "method must have exactly one receiver")
+                       check.error(recvList[len(recvList)-1].Pos(), InvalidRecv, "method must have exactly one receiver")
                        fallthrough // continue with first receiver
                case 1:
                        recv = recvList[0]
@@ -203,26 +204,27 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
                sig.recv = recv
 
                // Delay validation of receiver type as it may cause premature expansion
-               // of types the receiver type is dependent on (see issues #51232, #51233).
+               // of types the receiver type is dependent on (see issues go.dev/issue/51232, go.dev/issue/51233).
                check.later(func() {
                        // spec: "The receiver type must be of the form T or *T where T is a type name."
                        rtyp, _ := deref(recv.typ)
-                       if rtyp == Typ[Invalid] {
+                       atyp := _Unalias(rtyp)
+                       if !isValid(atyp) {
                                return // error was reported before
                        }
                        // 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."
-                       switch T := rtyp.(type) {
+                       switch T := atyp.(type) {
                        case *Named:
                                // The receiver type may be an instantiated type referred to
                                // by an alias (which cannot have receiver parameters for now).
                                if T.TypeArgs() != nil && sig.RecvTypeParams() == nil {
-                                       check.errorf(recv, _InvalidRecv, "cannot define new methods on instantiated type %s", rtyp)
+                                       check.errorf(recv, InvalidRecv, "cannot define new methods on instantiated type %s", rtyp)
                                        break
                                }
                                if T.obj.pkg != check.pkg {
-                                       check.errorf(recv, _InvalidRecv, "cannot define new methods on non-local type %s", rtyp)
+                                       check.errorf(recv, InvalidRecv, "cannot define new methods on non-local type %s", rtyp)
                                        break
                                }
                                var cause string
@@ -240,12 +242,12 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
                                        unreachable()
                                }
                                if cause != "" {
-                                       check.errorf(recv, _InvalidRecv, "invalid receiver type %s (%s)", rtyp, cause)
+                                       check.errorf(recv, InvalidRecv, "invalid receiver type %s (%s)", rtyp, cause)
                                }
                        case *Basic:
-                               check.errorf(recv, _InvalidRecv, "cannot define new methods on non-local type %s", rtyp)
+                               check.errorf(recv, InvalidRecv, "cannot define new methods on non-local type %s", rtyp)
                        default:
-                               check.errorf(recv, _InvalidRecv, "invalid receiver type %s", recv.typ)
+                               check.errorf(recv, InvalidRecv, "invalid receiver type %s", recv.typ)
                        }
                }).describef(recv, "validate receiver %s", recv)
        }
@@ -276,7 +278,7 @@ func (check *Checker) collectParams(scope *Scope, list []*syntax.Field, variadic
                                if variadicOk && i == len(list)-1 {
                                        variadic = true
                                } else {
-                                       check.softErrorf(t, _MisplacedDotDotDot, "can only use ... with final parameter in list")
+                                       check.softErrorf(t, MisplacedDotDotDot, "can only use ... with final parameter in list")
                                        // ignore ... and continue
                                }
                        }
@@ -288,7 +290,7 @@ func (check *Checker) collectParams(scope *Scope, list []*syntax.Field, variadic
                        // named parameter
                        name := field.Name.Value
                        if name == "" {
-                               check.error(field.Name, 0, invalidAST+"anonymous parameter")
+                               check.error(field.Name, InvalidSyntaxTree, "anonymous parameter")
                                // ok to continue
                        }
                        par := NewParam(field.Name.Pos(), check.pkg, name, typ)
@@ -305,7 +307,7 @@ func (check *Checker) collectParams(scope *Scope, list []*syntax.Field, variadic
        }
 
        if named && anonymous {
-               check.error(list[0], 0, invalidAST+"list contains both named and anonymous parameters")
+               check.error(list[0], InvalidSyntaxTree, "list contains both named and anonymous parameters")
                // ok to continue
        }