harec

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

commit 86e487cc0d54597488c489fbe718a5de33a58d90
parent b01a5c5ab3965879b62fe5bb64a0811e35d78d04
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 23 Feb 2021 13:33:55 -0500

tests/23-errors: add error propagation test

Diffstat:
Msrc/types.c | 2+-
Mtests/23-errors.ha | 21++++++++++++++++++++-
2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/types.c b/src/types.c @@ -417,7 +417,7 @@ type_hash(const struct type *type) static const struct type * strip_flags(const struct type *t, struct type *secondary) { - if (!t->flags) { + if (!t->flags || t->storage == STORAGE_ALIAS) { return t; } *secondary = *t; diff --git a/tests/23-errors.ha b/tests/23-errors.ha @@ -7,7 +7,26 @@ fn assignability() void = { assert(a == b); }; +type error = void!; + +fn err_if_false(in: bool) (error | int) = { + if (in) { + return 1337; + }; + return error; +}; + +fn indirect(in: bool) (error | int) = { + let x = err_if_false(in)?; + return x; +}; + +fn propagate() void = { + assert(indirect(true) as int == 1337); + assert(indirect(false) is error); +}; + export fn main() void = { assignability(); - // TODO: Expand with tests for the ? operator + propagate(); };