Skip to content

Commit 3e10918

Browse files
committed
cue/parser: better error messages for use of deprecated constructs
Also: - detects old-style aliases in one more case - does not unconditionally suggest the use of using v0.2.2 for cue fix, as newer versions work too in most cases. - updates the current version: not really necessary, as there isn't anything that was depracated since. Fixes #945 Change-Id: I555c91d979ee8c16c236accc63683d11a585d9a7 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9686 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent c2a68a9 commit 3e10918

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

cue/parser/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ type DeprecationError struct {
9494
}
9595

9696
func (e *DeprecationError) Error() string {
97-
return "try running `cue fix` using CUE v0.2.2 on the file or module to upgrade"
97+
return "try running `cue fix` (possibly with an earlier version, like v0.2.2) to upgrade"
9898
}
9999

100100
// Latest specifies the latest version of the parser, effectively setting
101101
// the strictest implementation.
102102
const Latest = latest
103103

104-
const latest = 1000
104+
const latest = -600
105105

106106
// FileOffset specifies the File position info to use.
107107
func FileOffset(pos int) Option {

cue/parser/parser.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func (p *parser) assertV0(pos token.Pos, minor, patch int, name string) {
401401
if p.version != 0 && p.version > v {
402402
p.errors = errors.Append(p.errors,
403403
errors.Wrapf(&DeprecationError{v}, pos,
404-
"%s deprecated as of v0.%d.%d", name, minor, patch+1))
404+
"use of deprecated %s (deprecated as of v0.%d.%d)", name, minor, patch+1))
405405
}
406406
}
407407

@@ -849,6 +849,7 @@ func (p *parser) parseField() (decl ast.Decl) {
849849
expr = p.parseRHS()
850850
}
851851
if a, ok := expr.(*ast.Alias); ok {
852+
p.assertV0(a.Pos(), 1, 3, `old-style alias; use "let X = expr" instead`)
852853
p.consumeDeclComma()
853854
return a
854855
}
@@ -876,8 +877,7 @@ func (p *parser) parseField() (decl ast.Decl) {
876877

877878
case token.RBRACE, token.EOF:
878879
if a, ok := expr.(*ast.Alias); ok {
879-
p.assertV0(p.pos, 1, 3, `old-style alias; use "let X = expr"`)
880-
880+
p.assertV0(a.Pos(), 1, 3, `old-style alias; use "let X = expr" instead`)
881881
return a
882882
}
883883
switch tok {
@@ -897,7 +897,7 @@ func (p *parser) parseField() (decl ast.Decl) {
897897
m.TokenPos = p.pos
898898
m.Token = p.tok
899899
if p.tok == token.ISA {
900-
p.assertV0(p.pos, 2, 0, "use of '::'")
900+
p.assertV0(p.pos, 2, 0, "'::'")
901901
}
902902
if p.tok != token.COLON && p.tok != token.ISA {
903903
p.errorExpected(pos, "':' or '::'")
@@ -930,7 +930,7 @@ func (p *parser) parseField() (decl ast.Decl) {
930930
m.TokenPos = p.pos
931931
m.Token = p.tok
932932
if p.tok == token.ISA {
933-
p.assertV0(p.pos, 2, 0, "use of '::'")
933+
p.assertV0(p.pos, 2, 0, "'::'")
934934
}
935935
if p.tok != token.COLON && p.tok != token.ISA {
936936
if p.tok.IsLiteral() {

cue/parser/parser_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,12 @@ func TestStrict(t *testing.T) {
658658
`a b c: 2`},
659659
{"reserved identifiers",
660660
`__foo: 3`},
661+
{"old-style definition",
662+
`foo :: 3`},
663+
{"old-style alias 1",
664+
`X=3`},
665+
{"old-style alias 2",
666+
`X={}`},
661667
}
662668
for _, tc := range testCases {
663669
t.Run(tc.desc, func(t *testing.T) {

0 commit comments

Comments
 (0)