1
0
mirror of https://github.com/golang/go synced 2024-11-18 22:04:43 -07:00

go/types: fix internal inInteger operand predicate

Backport of https://go-review.googlesource.com/#/c/12045/

Fixes golang/go#11594.

Change-Id: I3c81e2b1bbdc084d4a323fd963c1c780054ce223
Reviewed-on: https://go-review.googlesource.com/12046
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Robert Griesemer 2015-07-20 16:23:50 -07:00
parent 87156cb766
commit 436a79e5dd
3 changed files with 12 additions and 2 deletions

View File

@ -279,9 +279,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 a 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
}

View 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
)

View 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
}