Skip to content

Commit eb30fda

Browse files
committed
go/types: in string(x) conversions, x must be of integer type
Port of https://go-review.googlesource.com/11365 Fixes #11357. Change-Id: Icd20fa038696a8853d1d14477e1c1132938b3e2e Reviewed-on: https://go-review.googlesource.com/11368 Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent 4ba1f25 commit eb30fda

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Diff for: src/go/types/conversions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (check *Checker) conversion(x *operand, T Type) {
2020
switch t := T.Underlying().(*Basic); {
2121
case representableConst(x.val, check.conf, t.kind, &x.val):
2222
ok = true
23-
case x.isInteger() && isString(t):
23+
case isInteger(x.typ) && isString(t):
2424
codepoint := int64(-1)
2525
if i, ok := exact.Int64Val(x.val); ok {
2626
codepoint = i

Diff for: src/go/types/testdata/conversions.src

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func string_conversions() {
3232
const _ = string(true /* ERROR "cannot convert" */ )
3333
const _ = string(1.2 /* ERROR "cannot convert" */ )
3434
const _ = string(nil /* ERROR "cannot convert" */ )
35+
36+
// issues 11357, 11353: argument must be of integer type
37+
_ = string(0.0 /* ERROR "cannot convert" */ )
38+
_ = string(0i /* ERROR "cannot convert" */ )
39+
_ = string(1 /* ERROR "cannot convert" */ + 2i)
3540
}
3641

3742
func interface_conversions() {

0 commit comments

Comments
 (0)