harec

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

commit cb636689bcb1147378d48c1a9bc3a318a0012adc
parent e914d9af71cb609b90392bb99f63b8501a33ec5d
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Sun,  5 Feb 2023 15:51:36 +0100

lex: explicitly report numeric literal errors

T_ERROR isn't really used as an error, so that should not be relied on.

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Msrc/lex.c | 4+---
Mtests/00-constants.ha | 6++++++
2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/lex.c b/src/lex.c @@ -424,9 +424,7 @@ lex_literal(struct lexer *lexer, struct token *out) finalize: if (!started) { - out->token = T_ERROR; - consume(lexer, -1); - return out->token; + error(&out->loc, "Invalid literal"); } lexer->require_int = false; out->token = T_LITERAL; diff --git a/tests/00-constants.ha b/tests/00-constants.ha @@ -162,6 +162,12 @@ fn basics() void = { "let x = 0xu64;", "let x = 0be+0;", "let x = 0bf64;", + + // invalid digits in smaller bases + "let x = 0b41;", + "let x = 0b14;", + "let x = 0o82;", + "let x = 0o28;", ]; for (let i = 0z; i < len(failures); i += 1) { assert(compile(failures[i]) as exited != EXIT_SUCCESS);