go.tools/go/types: constant shifts always produce integers (bug fix)
R=adonovan CC=golang-dev https://golang.org/cl/12025044
This commit is contained in:
parent
30c6d6350d
commit
7a1a18283b
|
@ -546,7 +546,13 @@ func (check *checker) shift(x, y *operand, op token.Token) {
|
||||||
x.mode = invalid
|
x.mode = invalid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// everything's ok
|
// The lhs is representable as an integer but may not be an integer
|
||||||
|
// (e.g., 2.0, an untyped float) - this can only happen for untyped
|
||||||
|
// non-integer numeric constants. Correct the type so that the shift
|
||||||
|
// result is of integer type.
|
||||||
|
if !isInteger(x.typ) {
|
||||||
|
x.typ = Typ[UntypedInt]
|
||||||
|
}
|
||||||
x.val = exact.Shift(x.val, op, uint(s))
|
x.val = exact.Shift(x.val, op, uint(s))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,10 +63,6 @@ func TestStdtest(t *testing.T) {
|
||||||
case "map1.go":
|
case "map1.go":
|
||||||
// TODO(gri) fix map key checking
|
// TODO(gri) fix map key checking
|
||||||
continue
|
continue
|
||||||
case "shift2.go":
|
|
||||||
// TODO(gri) fix constant shift expression error
|
|
||||||
// (default type for 1.0<<1 is int, not float64).
|
|
||||||
continue
|
|
||||||
case "sizeof.go", "switch.go":
|
case "sizeof.go", "switch.go":
|
||||||
// TODO(gri) tone down duplicate checking in expression switches
|
// TODO(gri) tone down duplicate checking in expression switches
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -4,8 +4,31 @@
|
||||||
|
|
||||||
package shifts
|
package shifts
|
||||||
|
|
||||||
|
func shifts0() {
|
||||||
|
// basic constant shifts
|
||||||
|
const (
|
||||||
|
s = 10
|
||||||
|
_ = 0<<0
|
||||||
|
_ = 1<<s
|
||||||
|
_ = 1<<- /* ERROR "stupid shift" */ 1
|
||||||
|
_ = 2.0<<1
|
||||||
|
|
||||||
|
_ int = 2<<s
|
||||||
|
_ float32 = 2<<s
|
||||||
|
_ complex64 = 2<<s
|
||||||
|
|
||||||
|
_ int = 2.0<<s
|
||||||
|
_ float32 = 2.0<<s
|
||||||
|
_ complex64 = 2.0<<s
|
||||||
|
|
||||||
|
_ int = 'a'<<s
|
||||||
|
_ float32 = 'a'<<s
|
||||||
|
_ complex64 = 'a'<<s
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func shifts1() {
|
func shifts1() {
|
||||||
// basics
|
// basic non-constant shifts
|
||||||
var (
|
var (
|
||||||
i0 int
|
i0 int
|
||||||
u0 uint
|
u0 uint
|
||||||
|
|
Loading…
Reference in New Issue