aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/expr.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-02-03 14:56:13 -0800
committerRobert Griesemer <gri@golang.org>2021-02-04 22:20:33 +0000
commit1ff2fdaaf189e0d7ec73bdbff72558363239f48b (patch)
tree42512eabd1fa092e171cc296c2d1cfad86ec6220 /src/cmd/compile/internal/types2/expr.go
parent370e9f58432c51bf3d95308cdc7109e25cc141f6 (diff)
downloadgo-1ff2fdaaf189e0d7ec73bdbff72558363239f48b.tar.gz
go-1ff2fdaaf189e0d7ec73bdbff72558363239f48b.zip
[dev.typeparams] cmd/compile/internal/types2: add support for language version checking
Add the Config.Lang field which may be set to a Go version string, such as "go1.12". This is a string rather than explicit semantic version numbers (such as {1, 12}) for API robustness; a string is more flexible should we need more or different information. Add -lang flag to types2 package for use with (manual) testing when running "go test -run Check$ -lang=... -files=...". While changing flags, look for comma-separated (rather than space- separated) files when providing the -file flag. Check that numeric constant literals, signed shift counts are accepted according to the selected language version. Type alias declarations and overlapping embedded interfaces are not yet checked. Updates #31793. Change-Id: I9ff238ed38a88f377eb2267dc3e8816b89a40635 Reviewed-on: https://go-review.googlesource.com/c/go/+/289509 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/expr.go')
-rw-r--r--src/cmd/compile/internal/types2/expr.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go
index 679495d3f3..9889e3113d 100644
--- a/src/cmd/compile/internal/types2/expr.go
+++ b/src/cmd/compile/internal/types2/expr.go
@@ -816,6 +816,10 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
check.invalidOpf(y, "shift count %s must be integer", y)
x.mode = invalid
return
+ } else if !isUnsigned(y.typ) && !check.allowVersion(check.pkg, 1, 13) {
+ check.invalidOpf(y, "signed shift count %s requires go1.13 or later", y)
+ x.mode = invalid
+ return
}
if x.mode == constant_ {
@@ -1185,6 +1189,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin
}
switch e.Kind {
case syntax.IntLit, syntax.FloatLit, syntax.ImagLit:
+ check.langCompat(e)
// The max. mantissa precision for untyped numeric values
// is 512 bits, or 4048 bits for each of the two integer
// parts of a fraction for floating-point numbers that are