harec

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

commit eb82b4658a1712fe5fb0eb7f4b677fc1667502bd
parent 89b803775add158835e56f6194850eec6d58b437
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Mon,  3 May 2021 02:47:39 -0400

parse: make error types a prefix

Diffstat:
Msrc/parse.c | 14++++++++------
Msrc/typedef.c | 7+++----
Mtests/23-errors.ha | 6+++---
3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/parse.c b/src/parse.c @@ -598,6 +598,14 @@ parse_type(struct lexer *lexer) unlex(lexer, &tok); break; } + switch (lex(lexer, &tok)) { + case T_LNOT: + flags |= TYPE_ERROR; + break; + default: + unlex(lexer, &tok); + break; + } struct ast_type *type = NULL; bool noreturn = false, nullable = false, unwrap = false; switch (lex(lexer, &tok)) { @@ -704,12 +712,6 @@ parse_type(struct lexer *lexer) } type->flags |= flags; - if (lex(lexer, &tok) == T_LNOT) { - type->flags |= TYPE_ERROR; - } else { - unlex(lexer, &tok); - } - return type; } diff --git a/src/typedef.c b/src/typedef.c @@ -182,6 +182,9 @@ emit_type(const struct type *type, FILE *out) if (type->flags & TYPE_CONST) { fprintf(out, "const "); } + if (type->flags & TYPE_ERROR) { + fprintf(out, "!"); + } char *ident; switch (type->storage) { @@ -301,10 +304,6 @@ emit_type(const struct type *type, FILE *out) case STORAGE_ICONST: assert(0); // Invariant } - - if (type->flags & TYPE_ERROR) { - fprintf(out, "!"); - } } static void diff --git a/tests/23-errors.ha b/tests/23-errors.ha @@ -1,15 +1,15 @@ use rt; -type err_int = int!; +type err_int = !int; fn assignability() void = { // Error and non-error types are interchangable: - let a: int! = 10; + let a: !int = 10; let b: int = a; assert(a == b); }; -type error = void!; +type error = !void; fn err_if_false(in: bool) (error | int) = { if (in) {