aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2019-10-02 14:42:46 -0700
committerAndrew Bonventre <andybons@golang.org>2019-10-16 19:47:04 +0000
commit985804b4276e5da21f10a326ab9f5a5383b4377b (patch)
treef2aa4027d6a9c4efb7483c2852ec8757665a0ec9
parent2bbb57c9d4989fe4014d5da0d2a6bbc6acf28b9e (diff)
downloadgo-985804b4276e5da21f10a326ab9f5a5383b4377b.tar.gz
go-985804b4276e5da21f10a326ab9f5a5383b4377b.zip
[release-branch.go1.13] cmd/compile: better error message for language version errors
Fixes #33761. Updates #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: Ian Lance Taylor <iant@golang.org> (cherry picked from commit 27fc32ff01cc699e160890546816bd99d6c57823) Reviewed-on: https://go-review.googlesource.com/c/go/+/201480 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
-rw-r--r--src/cmd/compile/internal/gc/noder.go8
-rw-r--r--src/cmd/compile/internal/gc/subr.go5
-rw-r--r--src/cmd/compile/internal/gc/typecheck.go2
-rw-r--r--test/fixedbugs/issue31747.go10
4 files changed, 15 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go
index 93d355278e..6aca89cad9 100644
--- a/src/cmd/compile/internal/gc/noder.go
+++ b/src/cmd/compile/internal/gc/noder.go
@@ -1330,7 +1330,7 @@ func checkLangCompat(lit *syntax.BasicLit) {
}
// len(s) > 2
if strings.Contains(s, "_") {
- yyerror("underscores in numeric literals only supported as of -lang=go1.13")
+ yyerrorv("go1.13", "underscores in numeric literals")
return
}
if s[0] != '0' {
@@ -1338,15 +1338,15 @@ func checkLangCompat(lit *syntax.BasicLit) {
}
base := s[1]
if base == 'b' || base == 'B' {
- yyerror("binary literals only supported as of -lang=go1.13")
+ yyerrorv("go1.13", "binary literals")
return
}
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
}
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")
}
}
diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go
index f3ec21c7cb..d33fd4eb6c 100644
--- a/src/cmd/compile/internal/gc/subr.go
+++ b/src/cmd/compile/internal/gc/subr.go
@@ -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{}) {
yyerrorl(lineno, format, args...)
}
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go
index 4cb28d6100..223e5add36 100644
--- a/src/cmd/compile/internal/gc/typecheck.go
+++ b/src/cmd/compile/internal/gc/typecheck.go
@@ -632,7 +632,7 @@ func typecheck1(n *Node, top int) (res *Node) {
return n
}
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
return n
}
diff --git a/test/fixedbugs/issue31747.go b/test/fixedbugs/issue31747.go
index dfb585c613..420fe30735 100644
--- a/test/fixedbugs/issue31747.go
+++ b/test/fixedbugs/issue31747.go
@@ -8,11 +8,11 @@ package p
// numeric literals
const (
- _ = 1_000 // ERROR "underscores in numeric literals only supported as of -lang=go1.13"
- _ = 0b111 // ERROR "binary literals only supported as of -lang=go1.13"
- _ = 0o567 // ERROR "0o/0O-style octal 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 requires go1.13 or later"
+ _ = 0o567 // ERROR "0o/0O-style octal literals requires go1.13 or later"
_ = 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"
_ = 0O567 // ERROR "octal"
@@ -29,6 +29,6 @@ const (
// signed shift counts
var (
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"
)