diff --git a/cue/parser/parser.go b/cue/parser/parser.go index 1c4bbf14a..771b12d11 100644 --- a/cue/parser/parser.go +++ b/cue/parser/parser.go @@ -911,10 +911,10 @@ func (p *parser) parseField() (decl ast.Decl) { if expr == nil { expr = p.parseRHS() } - if a, ok := expr.(*ast.Alias); ok { - p.errf(a.Pos(), `pre-v0.2 alias; use "let X = expr" instead`) + if _, isAlias := expr.(*ast.Alias); isAlias { + p.errorExpected(p.pos, "label or ':'") p.consumeDeclComma() - return a + return &ast.BadDecl{From: pos, To: p.pos} } e := &ast.EmbedDecl{Expr: expr} p.consumeDeclComma() @@ -951,17 +951,15 @@ func (p *parser) parseField() (decl ast.Decl) { fallthrough case token.RBRACE, token.EOF: - if a, ok := expr.(*ast.Alias); ok { - p.errf(a.Pos(), `pre-v0.2 alias; use "let X = expr" instead`) - return a - } - switch tok { - case token.IDENT, token.LBRACK, token.LPAREN, - token.STRING, token.INTERPOLATION, - token.NULL, token.TRUE, token.FALSE, - token.FOR, token.IF, token.LET, token.IN, - token.TRY, token.ELSE, token.FALLBACK, token.OTHERWISE: - return &ast.EmbedDecl{Expr: expr} + if _, isAlias := expr.(*ast.Alias); !isAlias { + switch tok { + case token.IDENT, token.LBRACK, token.LPAREN, + token.STRING, token.INTERPOLATION, + token.NULL, token.TRUE, token.FALSE, + token.FOR, token.IF, token.LET, token.IN, + token.TRY, token.ELSE, token.FALLBACK, token.OTHERWISE: + return &ast.EmbedDecl{Expr: expr} + } } fallthrough diff --git a/cue/parser/parser_test.go b/cue/parser/parser_test.go index 63d993478..18184a5e0 100644 --- a/cue/parser/parser_test.go +++ b/cue/parser/parser_test.go @@ -1313,12 +1313,12 @@ bar: 2 { desc: "pre-v0.2 alias at top level", in: `X=3`, - out: "X=3\npre-v0.2 alias; use \"let X = expr\" instead", + out: "<*ast.BadDecl>\nexpected label or ':', found 'EOF'", }, { desc: "pre-v0.2 alias in struct", in: `a: { X={} }`, - out: "a: {X={}}\npre-v0.2 alias; use \"let X = expr\" instead", + out: "a: {<*ast.BadDecl>}\nexpected label or ':', found '}'", }, { desc: "postfix alias with experiment",