commit af65c5601d32f88b513136490d1d678e52c80c6f
parent 70a51c87202f7570ec83458c3e72c5532ebd9829
Author: Eyal Sawady <ecs@d2evs.net>
Date: Tue, 23 Feb 2021 14:40:20 -0500
Lower constants to int on ambiguous tagged unions
Fixes `let x: (i8 | int) = 0;`, necessary for `fmt::printf("{}", 1234);`
Diffstat:
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -998,11 +998,12 @@ lower_constant(const struct type *type, struct expression *expr)
for (const struct type_tagged_union *tu = &type->tagged; tu;
tu = tu->next) {
if (lower_constant(tu->type, expr)) {
- if (tag != NULL) {
- // Ambiguous
- return NULL;
+ if (tag == NULL) {
+ tag = tu->type;
+ continue;
}
- tag = tu->type;
+ // Ambiguous
+ return lower_constant(&builtin_type_int, expr);
}
}
return tag;