mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] go/types, cmd/compile/internal/types2: fix incorrect string(int) conversion (regression)
This is a 1:1 port of the go/types changes in https://golang.org/cl/272666 (master branch). Updates #42790. Change-Id: I5da372961df48129b25777ed705b84d7201393ec Reviewed-on: https://go-review.googlesource.com/c/go/+/272669 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
8fbdacf64c
commit
a324aebb7d
2 changed files with 16 additions and 16 deletions
|
|
@ -7,7 +7,10 @@
|
||||||
|
|
||||||
package types2
|
package types2
|
||||||
|
|
||||||
import "go/constant"
|
import (
|
||||||
|
"go/constant"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
// Conversion type-checks the conversion T(x).
|
// Conversion type-checks the conversion T(x).
|
||||||
// The result is in x.
|
// The result is in x.
|
||||||
|
|
@ -22,14 +25,11 @@ func (check *Checker) conversion(x *operand, T Type) {
|
||||||
case representableConst(x.val, check, t, &x.val):
|
case representableConst(x.val, check, t, &x.val):
|
||||||
ok = true
|
ok = true
|
||||||
case isInteger(x.typ) && isString(t):
|
case isInteger(x.typ) && isString(t):
|
||||||
codepoint := int64(-1)
|
codepoint := unicode.ReplacementChar
|
||||||
if i, ok := constant.Int64Val(x.val); ok {
|
if i, ok := constant.Uint64Val(x.val); ok && i <= unicode.MaxRune {
|
||||||
codepoint = i
|
codepoint = rune(i)
|
||||||
}
|
}
|
||||||
// If codepoint < 0 the absolute value is too large (or unknown) for
|
x.val = constant.MakeString(string(codepoint))
|
||||||
// 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)))
|
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
case x.convertibleTo(check, T):
|
case x.convertibleTo(check, T):
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@
|
||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import "go/constant"
|
import (
|
||||||
|
"go/constant"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
// Conversion type-checks the conversion T(x).
|
// Conversion type-checks the conversion T(x).
|
||||||
// The result is in 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):
|
case representableConst(x.val, check, t, &x.val):
|
||||||
ok = true
|
ok = true
|
||||||
case isInteger(x.typ) && isString(t):
|
case isInteger(x.typ) && isString(t):
|
||||||
codepoint := int64(-1)
|
codepoint := unicode.ReplacementChar
|
||||||
if i, ok := constant.Int64Val(x.val); ok {
|
if i, ok := constant.Uint64Val(x.val); ok && i <= unicode.MaxRune {
|
||||||
codepoint = i
|
codepoint = rune(i)
|
||||||
}
|
}
|
||||||
// If codepoint < 0 the absolute value is too large (or unknown) for
|
x.val = constant.MakeString(string(codepoint))
|
||||||
// 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)))
|
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
case x.convertibleTo(check, T):
|
case x.convertibleTo(check, T):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue