Commit 27fc32ff authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: better error message for language version errors

Fixes #33753.
Updates #31747.

Change-Id: Icc42b23405ead4f7f17b0ffa3611405454b6b271
Reviewed-on: https://go-review.googlesource.com/c/go/+/198491
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 64e598f7
...@@ -1327,7 +1327,7 @@ func checkLangCompat(lit *syntax.BasicLit) { ...@@ -1327,7 +1327,7 @@ func checkLangCompat(lit *syntax.BasicLit) {
} }
// len(s) > 2 // len(s) > 2
if strings.Contains(s, "_") { if strings.Contains(s, "_") {
yyerror("underscores in numeric literals only supported as of -lang=go1.13") yyerrorv("go1.13", "underscores in numeric literals")
return return
} }
if s[0] != '0' { if s[0] != '0' {
...@@ -1335,15 +1335,15 @@ func checkLangCompat(lit *syntax.BasicLit) { ...@@ -1335,15 +1335,15 @@ func checkLangCompat(lit *syntax.BasicLit) {
} }
base := s[1] base := s[1]
if base == 'b' || base == 'B' { if base == 'b' || base == 'B' {
yyerror("binary literals only supported as of -lang=go1.13") yyerrorv("go1.13", "binary literals")
return return
} }
if base == 'o' || base == 'O' { if base == 'o' || base == 'O' {
yyerror("0o/0O-style octal literals only supported as of -lang=go1.13") yyerrorv("go1.13", "0o/0O-style octal literals")
return return
} }
if lit.Kind != syntax.IntLit && (base == 'x' || base == 'X') { if lit.Kind != syntax.IntLit && (base == 'x' || base == 'X') {
yyerror("hexadecimal floating-point literals only supported as of -lang=go1.13") yyerrorv("go1.13", "hexadecimal floating-point literals")
} }
} }
......
...@@ -154,6 +154,11 @@ func yyerrorl(pos src.XPos, format string, args ...interface{}) { ...@@ -154,6 +154,11 @@ func yyerrorl(pos src.XPos, format string, args ...interface{}) {
} }
} }
func yyerrorv(lang string, format string, args ...interface{}) {
what := fmt.Sprintf(format, args...)
yyerrorl(lineno, "%s requires %s or later (-lang was set to %s; check go.mod)", what, lang, flag_lang)
}
func yyerror(format string, args ...interface{}) { func yyerror(format string, args ...interface{}) {
yyerrorl(lineno, format, args...) yyerrorl(lineno, format, args...)
} }
......
...@@ -604,7 +604,7 @@ func typecheck1(n *Node, top int) (res *Node) { ...@@ -604,7 +604,7 @@ func typecheck1(n *Node, top int) (res *Node) {
return n return n
} }
if t.IsSigned() && !langSupported(1, 13) { if t.IsSigned() && !langSupported(1, 13) {
yyerror("invalid operation: %v (signed shift count type %v, only supported as of -lang=go1.13)", n, r.Type) yyerrorv("go1.13", "invalid operation: %v (signed shift count type %v)", n, r.Type)
n.Type = nil n.Type = nil
return n return n
} }
......
...@@ -8,11 +8,11 @@ package p ...@@ -8,11 +8,11 @@ package p
// numeric literals // numeric literals
const ( const (
_ = 1_000 // ERROR "underscores in numeric literals only supported as of -lang=go1.13" _ = 1_000 // ERROR "underscores in numeric literals requires go1.13 or later \(-lang was set to go1.12; check go.mod\)"
_ = 0b111 // ERROR "binary literals only supported as of -lang=go1.13" _ = 0b111 // ERROR "binary literals requires go1.13 or later"
_ = 0o567 // ERROR "0o/0O-style octal literals only supported as of -lang=go1.13" _ = 0o567 // ERROR "0o/0O-style octal literals requires go1.13 or later"
_ = 0xabc // ok _ = 0xabc // ok
_ = 0x0p1 // ERROR "hexadecimal floating-point literals only supported as of -lang=go1.13" _ = 0x0p1 // ERROR "hexadecimal floating-point literals requires go1.13 or later"
_ = 0B111 // ERROR "binary" _ = 0B111 // ERROR "binary"
_ = 0O567 // ERROR "octal" _ = 0O567 // ERROR "octal"
...@@ -29,6 +29,6 @@ const ( ...@@ -29,6 +29,6 @@ const (
// signed shift counts // signed shift counts
var ( var (
s int s int
_ = 1 << s // ERROR "signed shift count type int, only supported as of -lang=go1.13" _ = 1 << s // ERROR "invalid operation: 1 << s \(signed shift count type int\) requires go1.13 or later"
_ = 1 >> s // ERROR "signed shift count" _ = 1 >> s // ERROR "signed shift count"
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment