commit c2e039cbcf08647b105e5bfd07fbc16e063b5424 parent c2c10365bbd3f898fe5bf7d579dfb98375123564 Author: Eyal Sawady <ecs@d2evs.net> Date: Fri, 26 Feb 2021 18:57:59 -0500 check: implement tagged union hints for tuples Diffstat:
M | src/check.c | | | 27 | +++++++++++++++++++++++++++ |
1 file changed, 27 insertions(+), 0 deletions(-)
diff --git a/src/check.c b/src/check.c @@ -2042,6 +2042,33 @@ check_expr_tuple(struct context *ctx, expr->result = type_store_lookup_tuple(ctx->store, &result); } + if (hint && type_dealias(hint)->storage == STORAGE_TAGGED) { + for (const struct type_tagged_union *tu = + &type_dealias(hint)->tagged; + tu; tu = tu->next) { + if (type_dealias(tu->type)->storage != STORAGE_TUPLE) { + continue; + } + const struct type_tuple *ttuple = + &type_dealias(tu->type)->tuple; + const struct expression_tuple *etuple = &expr->tuple; + bool valid = true; + while (etuple) { + if (!ttuple || !type_is_assignable(ttuple->type, + etuple->value->result)) { + valid = false; + break; + } + ttuple = ttuple->next; + etuple = etuple->next; + } + if (valid) { + expr->result = type_dealias(tu->type); + break; + } + } + } + ttuple = &type_dealias(expr->result)->tuple; struct expression_tuple *etuple = &expr->tuple; const struct ast_expression_tuple *atuple = &aexpr->tuple;