aboutsummaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorzhouguangyuan <zhouguangyuan.xian@gmail.com>2021-11-21 21:06:27 +0800
committerEmmanuel Odeke <emmanuel@orijtech.com>2021-11-22 12:29:44 +0000
commitffb6c798281f1a3ec54421a11573cec7d517d117 (patch)
tree6bb28a29c8ab98865c126758f14dfda0cc79d5f4 /src/go
parente30ebaab0bd5d95178f77cf40998ab14a0341d17 (diff)
downloadgo-ffb6c798281f1a3ec54421a11573cec7d517d117.tar.gz
go-ffb6c798281f1a3ec54421a11573cec7d517d117.zip
go/types,types2: use allInteger to check type for shifted operand
Fixes: #49705 Change-Id: I35a1c5f29b57f3facc5e89d33a8dec88e0ff4afa Reviewed-on: https://go-review.googlesource.com/c/go/+/365895 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/go')
-rw-r--r--src/go/types/check_test.go1
-rw-r--r--src/go/types/expr.go2
-rw-r--r--src/go/types/testdata/fixedbugs/issue49705.go211
3 files changed, 13 insertions, 1 deletions
diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go
index 2f80d9b7b6..a3be47e371 100644
--- a/src/go/types/check_test.go
+++ b/src/go/types/check_test.go
@@ -205,6 +205,7 @@ func asGoVersion(s string) string {
// TODO(gri) enable as soon as the unified build supports this.
var excludedForUnifiedBuild = map[string]bool{
"issue47818.go2": true,
+ "issue49705.go2": true,
}
func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, manual bool, imp Importer) {
diff --git a/src/go/types/expr.go b/src/go/types/expr.go
index e93a2bc7c8..c49865aec6 100644
--- a/src/go/types/expr.go
+++ b/src/go/types/expr.go
@@ -565,7 +565,7 @@ func (check *Checker) updateExprType(x ast.Expr, typ Type, final bool) {
// If x is the lhs of a shift, its final type must be integer.
// We already know from the shift check that it is representable
// as an integer if it is a constant.
- if !isInteger(typ) {
+ if !allInteger(typ) {
check.invalidOp(x, _InvalidShiftOperand, "shifted operand %s (type %s) must be integer", x, typ)
return
}
diff --git a/src/go/types/testdata/fixedbugs/issue49705.go2 b/src/go/types/testdata/fixedbugs/issue49705.go2
new file mode 100644
index 0000000000..2b991b8722
--- /dev/null
+++ b/src/go/types/testdata/fixedbugs/issue49705.go2
@@ -0,0 +1,11 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+import "constraints"
+
+func shl[I constraints.Integer](n int) I {
+ return 1 << n
+}