harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 234202dfb456dc7498852a9699a8b14eac6b8541
parent 4143dee5add526f925872bf841776dc6c3a44c76
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  2 Feb 2021 16:29:23 -0500

check: simplify match compatibility evaluation

Diffstat:
Msrc/check.c | 26++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -1002,24 +1002,14 @@ check_expr_match(struct context *ctx, break; } } else { - bool valid = false; - switch (ctype->storage) { - case TYPE_STORAGE_TAGGED: - expect(&acase->type->loc, type_is_assignable(type, ctype), - "Invalid type for match case (match is not assignable to this type)"); - break; - default: - for (const struct type_tagged_union *tu = &type->tagged; - tu; tu = tu->next) { - if (tu->type == ctype) { - valid = true; - break; - } - } - expect(&acase->type->loc, valid, - "Invalid type for match case (not a member of the tagged union)"); - break; - } + // TODO: Assign a score to tagged compatibility + // and choose the branch with the highest score. + const struct type *intermediate; + expect(&acase->type->loc, type_is_assignable(type, ctype), + "Invalid type for match case (match is not assignable to this type)"); + intermediate = tagged_select_subtype(type, ctype); + expect(&acase->type->loc, intermediate->id == ctype->id, + "TODO: Compare with transitive tagged type"); } }