]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: in string(x) conversions, x must be of integer type
authorRobert Griesemer <gri@golang.org>
Tue, 23 Jun 2015 21:01:45 +0000 (14:01 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 23 Jun 2015 21:06:07 +0000 (21:06 +0000)
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>
src/go/types/conversions.go
src/go/types/testdata/conversions.src

index da65f4276eedff5b412bfb5bfc171903132960bd..f72751d532e4c15ac60b69135001ea0c1b6dace5 100644 (file)
@@ -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
index 4251424646ee5c4a734cbb1bf322835e85973487..e1336c0456adf7baada345f46f5da54d89c9b804 100644 (file)
@@ -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() {