harec

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

commit 98ec114e71df484f4e285be31be9569a6090b44a
parent 9e5f1f7497940ecb22780c77e52bb4b508ab1a4f
Author: Vlad-Stefan Harbuz <vlad@vladh.net>
Date:   Fri, 10 Jun 2022 19:41:52 +0100

tuples: Fix handling of incorrect type

Fixes: https://todo.sr.ht/~sircmpwn/hare/731
Signed-off-by: Vlad-Stefan Harbuz <vlad@vladh.net>

Diffstat:
Msrc/check.c | 5+++++
Mtests/21-tuples.ha | 5+++++
2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -1034,6 +1034,11 @@ check_binding_unpack(struct context *ctx, assert(binding->initializer->type == EXPR_CONSTANT); } + if (type->storage != STORAGE_TUPLE) { + error(ctx, abinding->initializer->loc, expr, + "Unable to unpack tuple with non-tuple type specifier"); + return; + } const struct type_tuple *type_tuple = &type->tuple; bool found_binding = false; while (cur) { diff --git a/tests/21-tuples.ha b/tests/21-tuples.ha @@ -139,6 +139,11 @@ fn unpacking() void = { static let (a, _) = (2, getval()); }; ") != 0); + assert(rt::compile(" + export fn main() void = { + let (a, b): int = (2, 3); + }; + ") != 0); }; // Regression tests for miscellaneous compiler bugs