diff options
| author | Robert Griesemer <gri@golang.org> | 2020-11-23 15:48:37 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2020-11-24 00:50:11 +0000 |
| commit | 762eda346a9f4062feaa8a9fc0d17d72b11586f0 (patch) | |
| tree | d7de63419c1af84b8e2824daf0da180bea0b076d /src | |
| parent | 48a1a5189843571a08461a5756e5fe553f966c94 (diff) | |
| download | go-762eda346a9f4062feaa8a9fc0d17d72b11586f0.tar.xz | |
go/types: fix incorrect string(int) conversion (regression)
The bug was introduced by https://golang.org/cl/220844.
Fixes #42790.
Change-Id: I44d619a1a4d3f2aee1c5575d5cfddcc4ba10895f
Reviewed-on: https://go-review.googlesource.com/c/go/+/272666
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/go/types/conversions.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/go/types/conversions.go b/src/go/types/conversions.go index 0955391d7b..1cab1cc70f 100644 --- a/src/go/types/conversions.go +++ b/src/go/types/conversions.go @@ -6,7 +6,10 @@ package types -import "go/constant" +import ( + "go/constant" + "unicode" +) // Conversion type-checks the conversion T(x). // The result is in x. @@ -21,14 +24,11 @@ func (check *Checker) conversion(x *operand, T Type) { case representableConst(x.val, check, t, &x.val): ok = true case isInteger(x.typ) && isString(t): - codepoint := int64(-1) - if i, ok := constant.Int64Val(x.val); ok { - codepoint = i + codepoint := unicode.ReplacementChar + if i, ok := constant.Uint64Val(x.val); ok && i <= unicode.MaxRune { + codepoint = rune(i) } - // If codepoint < 0 the absolute value is too large (or unknown) for - // conversion. This is the same as converting any other out-of-range - // value - let string(codepoint) do the work. - x.val = constant.MakeString(string(rune(codepoint))) + x.val = constant.MakeString(string(codepoint)) ok = true } case x.convertibleTo(check, T): |
