harec

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

commit cf8f62f69138171d5983ab35ddf2bd6dda989fa9
parent 744b73c19ab30c5e361d5e418209cea170061035
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 31 Jan 2021 17:08:03 -0500

Fix match statements on tagged unions with pointers

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

diff --git a/src/check.c b/src/check.c @@ -941,13 +941,6 @@ check_expr_match(struct context *ctx, // TODO: Figure out alias semantics properly switch (ctype->storage) { - case TYPE_STORAGE_POINTER: - expect(&acase->type->loc, is_ptr, - "Not matching on pointer type"); - expect(&acase->type->loc, - type->pointer.referent == ctype->pointer.referent, - "Match case of incompatible pointer type"); - break; case TYPE_STORAGE_NULL: expect(&acase->type->loc, is_ptr, "Not matching on pointer type"); @@ -959,6 +952,14 @@ check_expr_match(struct context *ctx, type_is_assignable(type, ctype), "Invalid type for match case"); break; + case TYPE_STORAGE_POINTER: + if (is_ptr) { + expect(&acase->type->loc, + type->pointer.referent == ctype->pointer.referent, + "Match case of incompatible pointer type"); + break; + } + // Fallthrough default: expect(&acase->type->loc, !is_ptr, "Not matching on tagged union type");