aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/noder/helpers.go2
-rw-r--r--src/cmd/compile/internal/typecheck/const.go11
2 files changed, 7 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/noder/helpers.go b/src/cmd/compile/internal/noder/helpers.go
index 5349db3879..8aa93ef5dc 100644
--- a/src/cmd/compile/internal/noder/helpers.go
+++ b/src/cmd/compile/internal/noder/helpers.go
@@ -58,7 +58,7 @@ func FixValue(typ *types.Type, val constant.Value) constant.Value {
val = constant.ToComplex(val)
}
if !typ.IsUntyped() {
- val = typecheck.DefaultLit(ir.NewBasicLit(src.NoXPos, val), typ).Val()
+ val = typecheck.ConvertVal(val, typ, false)
}
ir.AssertValidTypeForConst(typ, val)
return val
diff --git a/src/cmd/compile/internal/typecheck/const.go b/src/cmd/compile/internal/typecheck/const.go
index 7ef913236e..2ac489aeef 100644
--- a/src/cmd/compile/internal/typecheck/const.go
+++ b/src/cmd/compile/internal/typecheck/const.go
@@ -113,7 +113,7 @@ func convlit1(n ir.Node, t *types.Type, explicit bool, context func() string) ir
base.Fatalf("unexpected untyped expression: %v", n)
case ir.OLITERAL:
- v := convertVal(n.Val(), t, explicit)
+ v := ConvertVal(n.Val(), t, explicit)
if v.Kind() == constant.Unknown {
n = ir.NewConstExpr(n.Val(), n)
break
@@ -219,12 +219,13 @@ func operandType(op ir.Op, t *types.Type) *types.Type {
return nil
}
-// convertVal converts v into a representation appropriate for t. If
-// no such representation exists, it returns Val{} instead.
+// ConvertVal converts v into a representation appropriate for t. If
+// no such representation exists, it returns constant.MakeUnknown()
+// instead.
//
// If explicit is true, then conversions from integer to string are
// also allowed.
-func convertVal(v constant.Value, t *types.Type, explicit bool) constant.Value {
+func ConvertVal(v constant.Value, t *types.Type, explicit bool) constant.Value {
switch ct := v.Kind(); ct {
case constant.Bool:
if t.IsBoolean() {
@@ -344,7 +345,7 @@ var overflowNames = [...]string{
// OrigConst returns an OLITERAL with orig n and value v.
func OrigConst(n ir.Node, v constant.Value) ir.Node {
lno := ir.SetPos(n)
- v = convertVal(v, n.Type(), false)
+ v = ConvertVal(v, n.Type(), false)
base.Pos = lno
switch v.Kind() {