From 8c8cd541fada27c1bb61d540ed3280e8165e388a Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 23 Jun 2015 13:17:41 -0700 Subject: [PATCH] go/types: in string(x) conversions, x must be of integer type Fixes golang/go#11357. Change-Id: Id6994a0fe3830cf56d3dbdd60a4dff89404e5a41 Reviewed-on: https://go-review.googlesource.com/11365 Reviewed-by: Alan Donovan --- go/types/conversions.go | 2 +- go/types/testdata/conversions.src | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/go/types/conversions.go b/go/types/conversions.go index f7b2a567..6e279ca3 100644 --- a/go/types/conversions.go +++ b/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/go/types/testdata/conversions.src b/go/types/testdata/conversions.src index 42514246..e1336c04 100644 --- a/go/types/testdata/conversions.src +++ b/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() {