package noder
import (
+ "go/constant"
+
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/syntax"
for _, name := range decl.NameList {
name, obj := g.def(name)
- name.SetVal(obj.(*types2.Const).Val())
+
+ // For untyped numeric constants, make sure the value
+ // representation matches what the rest of the
+ // compiler (really just iexport) expects.
+ // TODO(mdempsky): Revisit after #43891 is resolved.
+ val := obj.(*types2.Const).Val()
+ switch name.Type() {
+ case types.UntypedInt, types.UntypedRune:
+ val = constant.ToInt(val)
+ case types.UntypedFloat:
+ val = constant.ToFloat(val)
+ case types.UntypedComplex:
+ val = constant.ToComplex(val)
+ }
+ name.SetVal(val)
+
out.Append(ir.NewDecl(g.pos(decl), ir.ODCLCONST, name))
}
}
_ = real(0) // from bug report
_ = imag(0) // from bug report
+ // same as above, but exported for #43891
+ Real0 = real(0)
+ Imag0 = imag(0)
+
// if the arguments are untyped, the results must be untyped
// (and compatible with types that can represent the values)
_ int = real(1)