package types
-import "go/constant"
+import (
+ "go/constant"
+ "unicode"
+)
// Conversion type-checks the conversion T(x).
// The result is in x.
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):
--- /dev/null
+// compile
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+const _ = -uint(len(string(1<<32)) - len("\uFFFD"))