harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit 2c11aaca24c7072a24e55815756333f23827d001
parent c086f8d7c7c76db1b55649e6ca5a506e32333e39
Author: Pierre Curto <pierre.curto@gmail.com>
Date:   Thu, 24 Nov 2022 13:58:31 +0100

support untagged type in match case

Fixes: https://todo.sr.ht/~sircmpwn/hare/725

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>

Diffstat:
Msrc/gen.c | 6+++++-
Mtests/18-match.ha | 10++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/gen.c b/src/gen.c @@ -2462,6 +2462,10 @@ gen_nested_match_tests(struct gen_context *ctx, struct gen_value object, do { struct qbe_statement lsubtype; struct qbe_value bsubtype = mklabel(ctx, &lsubtype, "subtype.%d"); + + if (type_dealias(subtype)->storage != STORAGE_TAGGED) { + break; + } test = tagged_select_subtype(subtype, type); if (!test) { break; @@ -2472,7 +2476,7 @@ gen_nested_match_tests(struct gen_context *ctx, struct gen_value object, pushi(ctx->current, NULL, Q_JNZ, &qmatch, &bsubtype, &bnext, NULL); push(&ctx->current->body, &lsubtype); - if (test->id != type->id && type_dealias(test)-> id != type->id) { + if (test->id != type->id && type_dealias(test)->id != type->id) { struct qbe_value offs = constl(subtype->align); pushi(ctx->current, &subval, Q_ADD, &subval, &offs, NULL); pushi(ctx->current, &temp, Q_LOADUW, &subval, NULL); diff --git a/tests/18-match.ha b/tests/18-match.ha @@ -8,6 +8,8 @@ type unsigned = (u8 | u16 | u32 | u64 | uint | size); type integer = (...signed | ...unsigned); type align_4 = (void | int); type align_8 = (void | int | i64); +type aint = int; +type bint = aint; fn tagged() void = { let cases: [3](int | uint | str) = [10i, 10u, "hello"]; @@ -186,6 +188,14 @@ fn transitivity() void = { abort(); }; assert(visit); + + let z: (bint | void) = 10; + match (z) { + case aint => + void; + case void => + abort(); + }; }; fn numeric() void = {