From eb30fda83e0e1cb30ad8ac1fb46c9606da84bc76 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 23 Jun 2015 14:01:45 -0700 Subject: [PATCH] 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 --- src/go/types/conversions.go | 2 +- src/go/types/testdata/conversions.src | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/go/types/conversions.go b/src/go/types/conversions.go index da65f4276e..f72751d532 100644 --- a/src/go/types/conversions.go +++ b/src/go/types/conversions.go @@ -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 diff --git a/src/go/types/testdata/conversions.src b/src/go/types/testdata/conversions.src index 4251424646..e1336c0456 100644 --- a/src/go/types/testdata/conversions.src +++ b/src/go/types/testdata/conversions.src @@ -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() { -- 2.50.0