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 <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
diff --git a/cue/parser/interface.go b/cue/parser/interface.go
index 2fad239..8695a6c 100644
--- a/cue/parser/interface.go
+++ b/cue/parser/interface.go
@@ -94,14 +94,14 @@
 }
 
 func (e *DeprecationError) Error() string {
-	return "try running `cue fix` using CUE v0.2.2 on the file or module to upgrade"
+	return "try running `cue fix` (possibly with an earlier version, like v0.2.2) to upgrade"
 }
 
 // Latest specifies the latest version of the parser, effectively setting
 // the strictest implementation.
 const Latest = latest
 
-const latest = 1000
+const latest = -600
 
 // FileOffset specifies the File position info to use.
 func FileOffset(pos int) Option {
diff --git a/cue/parser/parser.go b/cue/parser/parser.go
index 6a852a2..6ba99cd 100644
--- a/cue/parser/parser.go
+++ b/cue/parser/parser.go
@@ -401,7 +401,7 @@
 	if p.version != 0 && p.version > v {
 		p.errors = errors.Append(p.errors,
 			errors.Wrapf(&DeprecationError{v}, pos,
-				"%s deprecated as of v0.%d.%d", name, minor, patch+1))
+				"use of deprecated %s (deprecated as of v0.%d.%d)", name, minor, patch+1))
 	}
 }
 
@@ -849,6 +849,7 @@
 			expr = p.parseRHS()
 		}
 		if a, ok := expr.(*ast.Alias); ok {
+			p.assertV0(a.Pos(), 1, 3, `old-style alias; use "let X = expr" instead`)
 			p.consumeDeclComma()
 			return a
 		}
@@ -876,8 +877,7 @@
 
 	case token.RBRACE, token.EOF:
 		if a, ok := expr.(*ast.Alias); ok {
-			p.assertV0(p.pos, 1, 3, `old-style alias; use "let X = expr"`)
-
+			p.assertV0(a.Pos(), 1, 3, `old-style alias; use "let X = expr" instead`)
 			return a
 		}
 		switch tok {
@@ -897,7 +897,7 @@
 	m.TokenPos = p.pos
 	m.Token = p.tok
 	if p.tok == token.ISA {
-		p.assertV0(p.pos, 2, 0, "use of '::'")
+		p.assertV0(p.pos, 2, 0, "'::'")
 	}
 	if p.tok != token.COLON && p.tok != token.ISA {
 		p.errorExpected(pos, "':' or '::'")
@@ -930,7 +930,7 @@
 		m.TokenPos = p.pos
 		m.Token = p.tok
 		if p.tok == token.ISA {
-			p.assertV0(p.pos, 2, 0, "use of '::'")
+			p.assertV0(p.pos, 2, 0, "'::'")
 		}
 		if p.tok != token.COLON && p.tok != token.ISA {
 			if p.tok.IsLiteral() {
diff --git a/cue/parser/parser_test.go b/cue/parser/parser_test.go
index d07d166..4f12c93 100644
--- a/cue/parser/parser_test.go
+++ b/cue/parser/parser_test.go
@@ -658,6 +658,12 @@
 			`a b c: 2`},
 		{"reserved identifiers",
 			`__foo: 3`},
+		{"old-style definition",
+			`foo :: 3`},
+		{"old-style alias 1",
+			`X=3`},
+		{"old-style alias 2",
+			`X={}`},
 	}
 	for _, tc := range testCases {
 		t.Run(tc.desc, func(t *testing.T) {