harec

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

commit c3d6383e8e1f2c9f67a278fda7ada71be182ad83
parent f7e8c9f1b41ff5c9430147fe483b1b890552a140
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  2 Feb 2021 17:25:52 -0500

Fix issue with unaliased match cases

Diffstat:
Msrc/gen.c | 4++++
Mtests/18-match.ha | 11++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/gen.c b/src/gen.c @@ -1529,6 +1529,10 @@ gen_match_tagged(struct gen_context *ctx, sbranch.name = strdup(genl(&slabel, &ctx->id, "match.subtype.%d")); test = tagged_select_subtype(subtype, _case->type); + if (!test && type_dealias(subtype)->id == _case->type->id) { + break; + } + constw(&match, test->id); pushi(ctx->current, &temp, Q_CEQW, &match, curtag, NULL); pushi(ctx->current, NULL, Q_JNZ, &temp, &sbranch, &fbranch, NULL); diff --git a/tests/18-match.ha b/tests/18-match.ha @@ -105,7 +105,6 @@ fn transitivity() void = { foo => abort(), bar => abort(), }; - x = foo; let visit = false; match (x) { @@ -128,6 +127,16 @@ fn transitivity() void = { }; assert(visit); + visit = false; + match (x) { + z: (foo | bar) => { + visit = true; + assert(z is bar); + }, + int => abort(), + }; + assert(visit); + let y: foobarbaz = 10; visit = false; match (y) {