~sircmpwn/harec unlisted

eb82b4658a1712fe5fb0eb7f4b677fc1667502bd — Eyal Sawady a month ago 89b8037
parse: make error types a prefix
3 files changed, 14 insertions(+), 13 deletions(-)

M src/parse.c
M src/typedef.c
M tests/23-errors.ha
M src/parse.c => src/parse.c +8 -6
@@ 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;
}


M src/typedef.c => src/typedef.c +3 -4
@@ 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

M tests/23-errors.ha => tests/23-errors.ha +3 -3
@@ 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) {