]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/compile/internal/types2/resolver.go
go/types, types2: introduce _Alias type node
[gostls13.git] / src / cmd / compile / internal / types2 / resolver.go
index d051fb50e1b5fca38620947c0d82822607bce2dc..e074b7548c05c0a5ac8bcdb48b88ffe445bfaa0b 100644 (file)
@@ -351,7 +351,7 @@ func (check *Checker) collectObjects() {
                                }
 
                                // declare all constants
-                               values := unpackExpr(last.Values)
+                               values := syntax.UnpackListExpr(last.Values)
                                for i, name := range s.NameList {
                                        obj := NewConst(name.Pos(), pkg, name.Value, nil, iota)
 
@@ -382,7 +382,7 @@ func (check *Checker) collectObjects() {
                                }
 
                                // declare all variables
-                               values := unpackExpr(s.Values)
+                               values := syntax.UnpackListExpr(s.Values)
                                for i, name := range s.NameList {
                                        obj := NewVar(name.Pos(), pkg, name.Value, nil)
                                        lhs[i] = obj
@@ -538,7 +538,7 @@ L: // unpack receiver type
        if ptyp, _ := rtyp.(*syntax.IndexExpr); ptyp != nil {
                rtyp = ptyp.X
                if unpackParams {
-                       for _, arg := range unpackExpr(ptyp.Index) {
+                       for _, arg := range syntax.UnpackListExpr(ptyp.Index) {
                                var par *syntax.Name
                                switch arg := arg.(type) {
                                case *syntax.Name:
@@ -588,7 +588,7 @@ func (check *Checker) resolveBaseTypeName(seenPtr bool, typ syntax.Expr, fileSco
                                return false, nil
                        }
                        ptr = true
-                       typ = unparen(pexpr.X) // continue with pointer base type
+                       typ = syntax.Unparen(pexpr.X) // continue with pointer base type
                }
 
                // typ must be a name, or a C.name cgo selector.
@@ -677,32 +677,39 @@ func (check *Checker) packageObjects() {
                }
        }
 
-       // We process non-alias type declarations first, followed by alias declarations,
-       // and then everything else. This appears to avoid most situations where the type
-       // of an alias is needed before it is available.
-       // There may still be cases where this is not good enough (see also go.dev/issue/25838).
-       // In those cases Checker.ident will report an error ("invalid use of type alias").
-       var aliasList []*TypeName
-       var othersList []Object // everything that's not a type
-       // phase 1: non-alias type declarations
-       for _, obj := range objList {
-               if tname, _ := obj.(*TypeName); tname != nil {
-                       if check.objMap[tname].tdecl.Alias {
-                               aliasList = append(aliasList, tname)
+       if check.conf._EnableAlias {
+               // With _Alias nodes we can process declarations in any order.
+               for _, obj := range objList {
+                       check.objDecl(obj, nil)
+               }
+       } else {
+               // Without _Alias nodes, we process non-alias type declarations first, followed by
+               // alias declarations, and then everything else. This appears to avoid most situations
+               // where the type of an alias is needed before it is available.
+               // There may still be cases where this is not good enough (see also go.dev/issue/25838).
+               // In those cases Checker.ident will report an error ("invalid use of type alias").
+               var aliasList []*TypeName
+               var othersList []Object // everything that's not a type
+               // phase 1: non-alias type declarations
+               for _, obj := range objList {
+                       if tname, _ := obj.(*TypeName); tname != nil {
+                               if check.objMap[tname].tdecl.Alias {
+                                       aliasList = append(aliasList, tname)
+                               } else {
+                                       check.objDecl(obj, nil)
+                               }
                        } else {
-                               check.objDecl(obj, nil)
+                               othersList = append(othersList, obj)
                        }
-               } else {
-                       othersList = append(othersList, obj)
                }
-       }
-       // phase 2: alias type declarations
-       for _, obj := range aliasList {
-               check.objDecl(obj, nil)
-       }
-       // phase 3: all other declarations
-       for _, obj := range othersList {
-               check.objDecl(obj, nil)
+               // phase 2: alias type declarations
+               for _, obj := range aliasList {
+                       check.objDecl(obj, nil)
+               }
+               // phase 3: all other declarations
+               for _, obj := range othersList {
+                       check.objDecl(obj, nil)
+               }
        }
 
        // At this point we may have a non-empty check.methods map; this means that not all