For #45114.
Fixes #45117.
Change-Id: I71d6650ae2c4c06952fce19959120f15f13c08a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/379256
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
{`package c5d; var _ = string(65)`, `65`, `untyped int`, `65`},
{`package c5e; var _ = string('A')`, `'A'`, `untyped rune`, `65`},
{`package c5f; type T string; var _ = T('A')`, `'A'`, `untyped rune`, `65`},
- {`package c5g; var s uint; var _ = string(1 << s)`, `1 << s`, `untyped int`, ``},
{`package d0; var _ = []byte("foo")`, `"foo"`, `string`, `"foo"`},
{`package d1; var _ = []byte(string("foo"))`, `"foo"`, `string`, `"foo"`},
// - For conversions of untyped constants to non-constant types, also
// use the default type (e.g., []byte("foo") should report string
// not []byte as type for the constant "foo").
- // - For integer to string conversions, keep the argument type.
+ // - For constant integer to string conversions, keep the argument type.
// (See also the TODO below.)
if x.typ == Typ[UntypedNil] {
// ok
} else if IsInterface(T) && !isTypeParam(T) || constArg && !isConstType(T) {
final = Default(x.typ)
- } else if isInteger(x.typ) && allString(T) {
+ } else if x.mode == constant_ && isInteger(x.typ) && allString(T) {
final = x.typ
}
check.updateExprType(x.expr, final, true)
var a = make([]int, 1<<s + 1.2 /* ERROR "truncated to int" */ )
var _ = a[1<<s - 2.3 /* ERROR "truncated to int" */ ]
var _ int = 1<<s + 3.4 /* ERROR "truncated to int" */
- var _ = string(1 << s)
+ var _ = string(1 /* ERROR shifted operand 1 .* must be integer */ << s)
var _ = string(1.0 /* ERROR "cannot convert" */ << s)
}
--- /dev/null
+// Copyright 2022 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
+
+var s uint
+var _ = string(1 /* ERROR shifted operand 1 .* must be integer */ << s)
{`package c5d; var _ = string(65)`, `65`, `untyped int`, `65`},
{`package c5e; var _ = string('A')`, `'A'`, `untyped rune`, `65`},
{`package c5f; type T string; var _ = T('A')`, `'A'`, `untyped rune`, `65`},
- {`package c5g; var s uint; var _ = string(1 << s)`, `1 << s`, `untyped int`, ``},
{`package d0; var _ = []byte("foo")`, `"foo"`, `string`, `"foo"`},
{`package d1; var _ = []byte(string("foo"))`, `"foo"`, `string`, `"foo"`},
// use the default type (e.g., []byte("foo") should report string
// not []byte as type for the constant "foo").
// - Keep untyped nil for untyped nil arguments.
- // - For integer to string conversions, keep the argument type.
+ // - For constant integer to string conversions, keep the argument type.
// (See also the TODO below.)
if IsInterface(T) && !isTypeParam(T) || constArg && !isConstType(T) || x.isNil() {
final = Default(x.typ) // default type of untyped nil is untyped nil
- } else if isInteger(x.typ) && allString(T) {
+ } else if x.mode == constant_ && isInteger(x.typ) && allString(T) {
final = x.typ
}
check.updateExprType(x.expr, final, true)
var a = make([]int, 1<<s + 1.2 /* ERROR "truncated to int" */ )
var _ = a[1<<s - 2.3 /* ERROR "truncated to int" */ ]
var _ int = 1<<s + 3.4 /* ERROR "truncated to int" */
- var _ = string(1 << s)
+ var _ = string(1 /* ERROR shifted operand 1 .* must be integer */ << s)
var _ = string(1.0 /* ERROR "cannot convert" */ << s)
}
--- /dev/null
+// Copyright 2022 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
+
+var s uint
+var _ = string(1 /* ERROR shifted operand 1 .* must be integer */ << s)
ss := 1 << s
y1 := float64(ss)
y2 := float64(1 << s) // ERROR "shift"
- // see issues #45114, #45117
- // y3 := string(1 << s) // DISABLED "shift"
- y3 := 0
+ y3 := string(1 << s) // ERROR "shift"
_, _, _, _, _ = s, ss, y1, y2, y3
}