harec

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

commit ff187a0794d2bf4a8811c26670d06323dbba68c4
parent 56df61bf43f74e2db69da74aba46bd7ee1c4e733
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 23 Feb 2021 08:03:33 -0500

Implement error type flag

Diffstat:
Minclude/types.h | 1+
Msrc/parse.c | 7+++++++
Msrc/type_store.c | 1+
Atests/23-errors.ha | 13+++++++++++++
Mtests/configure | 3++-
5 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/include/types.h b/include/types.h @@ -131,6 +131,7 @@ struct type_tagged_union { enum type_flags { TYPE_CONST = 1 << 0, + TYPE_ERROR = 1 << 1, }; struct type { diff --git a/src/parse.c b/src/parse.c @@ -729,6 +729,13 @@ parse_type(struct lexer *lexer) type->flags |= flags; trleave(TR_PARSE, "%s%s", type->flags & TYPE_CONST ? "const " : "", type_storage_unparse(type->storage)); + + if (lex(lexer, &tok) == T_LNOT) { + type->flags |= TYPE_ERROR; + } else { + unlex(lexer, &tok); + } + return type; } diff --git a/src/type_store.c b/src/type_store.c @@ -685,6 +685,7 @@ type_store_lookup_alias(struct type_store *store, }, .size = secondary->size, .align = secondary->align, + .flags = secondary->flags, }; struct type *type = (struct type *)type_store_lookup_type(store, &alias); if (type->alias.type == NULL) { diff --git a/tests/23-errors.ha b/tests/23-errors.ha @@ -0,0 +1,13 @@ +type err_int = int!; + +fn assignability() void = { + // Error and non-error types are interchangable: + let a: int! = 10; + let b: int = a; + assert(a == b); +}; + +export fn main() void = { + assignability(); + // TODO: Expand with tests for the ? operator +}; diff --git a/tests/configure b/tests/configure @@ -25,7 +25,8 @@ tests() { 19-append \ 20-if \ 21-tuples \ - 22-delete + 22-delete \ + 23-errors do cat <<EOF tests/$t: libhart.a tests/$t.ha