if v.U == nil {
break
}
- n.SetVal(v)
n.Type = t
+ n.SetVal(v)
return n
case OPLUS, ONEG, OBITNOT, ONOT, OREAL, OIMAG:
Xoffset: BADWIDTH,
}
n.SetVal(v)
- if vt := idealType(v.Ctype()); n.Type.IsUntyped() && n.Type != vt {
- Fatalf("untyped type mismatch, have: %v, want: %v", n.Type, vt)
- }
// Check range.
lno := setlineno(n)
}
}
+func assertRepresents(t *types.Type, v Val) {
+ if !represents(t, v) {
+ Fatalf("%v does not represent %v", t, v)
+ }
+}
+
+func represents(t *types.Type, v Val) bool {
+ if !t.IsUntyped() {
+ // TODO(mdempsky): Stricter handling of typed types.
+ return true
+ }
+
+ vt := idealType(v.Ctype())
+ return t == vt
+}
+
func setboolconst(n *Node, v bool) {
setconst(n, Val{U: v})
}
// nodlit returns a new untyped constant with value v.
func nodlit(v Val) *Node {
n := nod(OLITERAL, nil, nil)
- n.SetVal(v)
n.Type = idealType(v.Ctype())
+ n.SetVal(v)
return n
}
}
func (w *exportWriter) value(typ *types.Type, v Val) {
- if vt := idealType(v.Ctype()); typ.IsUntyped() && typ != vt {
- Fatalf("exporter: untyped type mismatch, have: %v, want: %v", typ, vt)
- }
+ assertRepresents(typ, v)
w.typ(typ)
// Each type has only one admissible constant representation,