Skip to content

Commit

Permalink
go/types: in string(x) conversions, x must be of integer type
Browse files Browse the repository at this point in the history
Fixes golang/go#11357.

Change-Id: Id6994a0fe3830cf56d3dbdd60a4dff89404e5a41
Reviewed-on: https://go-review.googlesource.com/11365
Reviewed-by: Alan Donovan <[email protected]>
  • Loading branch information
griesemer committed Jun 23, 2015
1 parent 6369699 commit 8c8cd54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go/types/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (check *Checker) conversion(x *operand, T Type) {
switch t := T.Underlying().(*Basic); {
case representableConst(x.val, check.conf, t.kind, &x.val):
ok = true
case x.isInteger() && isString(t):
case isInteger(x.typ) && isString(t):
codepoint := int64(-1)
if i, ok := exact.Int64Val(x.val); ok {
codepoint = i
Expand Down
5 changes: 5 additions & 0 deletions go/types/testdata/conversions.src
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func string_conversions() {
const _ = string(true /* ERROR "cannot convert" */ )
const _ = string(1.2 /* ERROR "cannot convert" */ )
const _ = string(nil /* ERROR "cannot convert" */ )

// issues 11357, 11353: argument must be of integer type
_ = string(0.0 /* ERROR "cannot convert" */ )
_ = string(0i /* ERROR "cannot convert" */ )
_ = string(1 /* ERROR "cannot convert" */ + 2i)
}

func interface_conversions() {
Expand Down

0 comments on commit 8c8cd54

Please sign in to comment.