commit f19a71026da1ec3e52aa4c6d8ecad76748d194e3
parent 8b6c4b113e1575cd38ab0cbcd864818ceb4608f8
Author: Eyal Sawady <ecs@d2evs.net>
Date: Sat, 10 Apr 2021 07:11:26 -0400
Fix tuples with tagged hints and 0-size fields
Diffstat:
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -2297,11 +2297,7 @@ check_expr_tuple(struct context *ctx,
if (hint && type_dealias(hint)->storage == STORAGE_TUPLE) {
expr->result = hint;
- } else {
- expr->result = type_store_lookup_tuple(ctx->store, &result);
- }
-
- if (hint && type_dealias(hint)->storage == STORAGE_TAGGED) {
+ } else if (hint && type_dealias(hint)->storage == STORAGE_TAGGED) {
for (const struct type_tagged_union *tu =
&type_dealias(hint)->tagged;
tu; tu = tu->next) {
@@ -2326,6 +2322,12 @@ check_expr_tuple(struct context *ctx,
break;
}
}
+ if (!expr->result) {
+ return error(aexpr->loc, expr, errors,
+ "Tuple value is not assignable to tagged union hint");
+ }
+ } else {
+ expr->result = type_store_lookup_tuple(ctx->store, &result);
}
ttuple = &type_dealias(expr->result)->tuple;
diff --git a/tests/21-tuples.ha b/tests/21-tuples.ha
@@ -25,10 +25,16 @@ fn funcs() void = {
assert(x.0 == 42 && x.1 == 1337);
};
+// Regression tests for miscellaneous compiler bugs
+fn regression() void = {
+ let a: (((int | void), int) | void) = (void, 0);
+};
+
export fn main() void = {
storage();
indexing();
funcs();
eval_expr_tuple();
eval_expr_access();
+ regression();
};