]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: fix internal inInteger operand predicate
authorRobert Griesemer <gri@golang.org>
Fri, 10 Jul 2015 22:11:06 +0000 (16:11 -0600)
committerAlan Donovan <adonovan@google.com>
Wed, 15 Jul 2015 02:25:47 +0000 (02:25 +0000)
When testing if a value is an integer, if the value is a constant,
don't ignore the type if it has one.

Fixes #11594.

Change-Id: I2ff387e4f9e8ab7cae35c4838350e0a1fce2e625
Reviewed-on: https://go-review.googlesource.com/12045
Reviewed-by: Alan Donovan <adonovan@google.com>
src/go/types/operand.go
src/go/types/testdata/decls0.src
src/go/types/testdata/shifts.src

index a7d3b0aaeea5679a158283bf1c314e1d51121561..afa92061423594a3abd619fc9549eac1347bd802 100644 (file)
@@ -278,9 +278,10 @@ func (x *operand) assignableTo(conf *Config, T Type) bool {
        return false
 }
 
-// isInteger reports whether x is a (typed or untyped) integer value.
+// isInteger reports whether x is value of integer type
+// or an untyped constant representable as an integer.
 func (x *operand) isInteger() bool {
        return x.mode == invalid ||
                isInteger(x.typ) ||
-               x.mode == constant && representableConst(x.val, nil, UntypedInt, nil) // no *Config required for UntypedInt
+               isUntyped(x.typ) && x.mode == constant && representableConst(x.val, nil, UntypedInt, nil) // no *Config required for UntypedInt
 }
index f1df3ea7033db8fdcade60f2cc8f3b0d43bdbaea..21baafe2794416922ae840c7de44c0c5e7017c9a 100644 (file)
@@ -53,6 +53,7 @@ type (
        iA1 [1 /* ERROR "invalid array length" */ <<100]int
        iA2 [- /* ERROR "invalid array length" */ 1]complex128
        iA3 ["foo" /* ERROR "must be integer" */ ]string
+       iA4 [float64 /* ERROR "must be integer" */ (0)]int
 )
 
 
index 2df2ccde0b7659e58f736a05eca05887125059bb..64865fc07b9d285274067aafd767b245ef9dd26d 100644 (file)
@@ -331,3 +331,11 @@ func issue11325() {
        _ = 1. >> 1.
        _ = 1.1 /* ERROR "must be integer" */ >> 1
 }
+
+func issue11594() {
+       var _ = complex64 /* ERROR "must be integer" */ (1) << 2 // example from issue 11594
+       _ = float32 /* ERROR "must be integer" */ (0) << 1
+       _ = float64 /* ERROR "must be integer" */ (0) >> 2
+       _ = complex64 /* ERROR "must be integer" */ (0) << 3
+       _ = complex64 /* ERROR "must be integer" */ (0) >> 4
+}
\ No newline at end of file