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
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
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() {
// 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() {