X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fcompile%2Finternal%2Ftypes2%2Fdecl.go;h=6fd2c2cad8f112e1bd1fed4ed4b31520c33805cd;hb=bea55136b2d50fc514ddfba4380311295975a660;hp=ed6b96eb090aa2c790a00b1b851de3d913a5f90a;hpb=1b03ec8a25412342ca072c0860bdf046d58e82ac;p=gostls13.git diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go index ed6b96eb09..6fd2c2cad8 100644 --- a/src/cmd/compile/internal/types2/decl.go +++ b/src/cmd/compile/internal/types2/decl.go @@ -251,10 +251,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.Alias // 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.Alias // package-level object + } else { + alias = obj.IsAlias() // function local object + } } if !alias { ndef++ @@ -322,7 +326,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 @@ -495,20 +503,32 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *TypeN _ = check.isImportedConstraint(rhs) && check.verifyVersionf(tdecl.Type, go1_18, "using type constraint %s", rhs) }).describef(obj, "validType(%s)", obj.Name()) - alias := tdecl.Alias - if alias && tdecl.TParamList != nil { + aliasDecl := tdecl.Alias + if aliasDecl && tdecl.TParamList != nil { // The parser will ensure this but we may still get an invalid AST. // Complain and continue as regular type definition. check.error(tdecl, BadDecl, "generic type cannot be alias") - alias = false + aliasDecl = false } // alias declaration - if alias { + if aliasDecl { check.verifyVersionf(tdecl, 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 }