X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fgo%2Ftypes%2Fdecl.go;h=16f250aee2c602a7aa8487f34a972f9dfb2d2d28;hb=bea55136b2d50fc514ddfba4380311295975a660;hp=7d6a2aa039852c7e2c4b59e4a2c98775f3c72efe;hpb=1b03ec8a25412342ca072c0860bdf046d58e82ac;p=gostls13.git diff --git a/src/go/types/decl.go b/src/go/types/decl.go index 7d6a2aa039..16f250aee2 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -249,10 +249,14 @@ loop: // the syntactic information. We should consider storing // this information explicitly in the object. var alias bool - if d := check.objMap[obj]; d != nil { - alias = d.tdecl.Assign.IsValid() // package-level object + if check.conf._EnableAlias { + alias = obj.IsAlias() } else { - alias = obj.IsAlias() // function local object + if d := check.objMap[obj]; d != nil { + alias = d.tdecl.Assign.IsValid() // package-level object + } else { + alias = obj.IsAlias() // function local object + } } if !alias { ndef++ @@ -320,7 +324,11 @@ func (check *Checker) cycleError(cycle []Object) { // If obj is a type alias, mark it as valid (not broken) in order to avoid follow-on errors. tname, _ := obj.(*TypeName) if tname != nil && tname.IsAlias() { - check.validAlias(tname, Typ[Invalid]) + // If we use Alias nodes, it is initialized with Typ[Invalid]. + // TODO(gri) Adjust this code if we initialize with nil. + if !check.conf._EnableAlias { + check.validAlias(tname, Typ[Invalid]) + } } // report a more concise error for self references @@ -564,20 +572,32 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *TypeName _ = check.isImportedConstraint(rhs) && check.verifyVersionf(tdecl.Type, go1_18, "using type constraint %s", rhs) }).describef(obj, "validType(%s)", obj.Name()) - alias := tdecl.Assign.IsValid() - if alias && tdecl.TypeParams.NumFields() != 0 { + aliasDecl := tdecl.Assign.IsValid() + if aliasDecl && tdecl.TypeParams.NumFields() != 0 { // The parser will ensure this but we may still get an invalid AST. // Complain and continue as regular type definition. check.error(atPos(tdecl.Assign), BadDecl, "generic type cannot be alias") - alias = false + aliasDecl = false } // alias declaration - if alias { + if aliasDecl { check.verifyVersionf(atPos(tdecl.Assign), go1_9, "type aliases") - check.brokenAlias(obj) - rhs = check.typ(tdecl.Type) - check.validAlias(obj, rhs) + if check.conf._EnableAlias { + // TODO(gri) Should be able to use nil instead of Typ[Invalid] to mark + // the alias as incomplete. Currently this causes problems + // with certain cycles. Investigate. + alias := check.newAlias(obj, Typ[Invalid]) + setDefType(def, alias) + rhs = check.definedType(tdecl.Type, obj) + assert(rhs != nil) + alias.fromRHS = rhs + _Unalias(alias) // resolve alias.actual + } else { + check.brokenAlias(obj) + rhs = check.typ(tdecl.Type) + check.validAlias(obj, rhs) + } return }