commit 138a84601a9f4dd7d8908346710885e15ef4456b
parent 317f8049838f5c687c1c7f82b309a9bfca8ec49c
Author: Bor Grošelj Simić <bgs@turminal.net>
Date: Wed, 8 Feb 2023 00:14:15 +0100
hare::parse: parse type assertions to null
Implements: https://todo.sr.ht/~sircmpwn/hare/658
Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
Diffstat:
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/hare/parse/+test/expr.ha b/hare/parse/+test/expr.ha
@@ -93,8 +93,11 @@
roundtrip("export fn main() void = void: int;\n\n"
"export fn main() void = void as int;\n\n"
"export fn main() void = void is int;\n\n"
+ "export fn main() void = void as null;\n\n"
+ "export fn main() void = void is null;\n\n"
"export fn main() void = void: int: uint: u16: u8;\n\n"
"export fn main() void = void: int as uint: u16 is u8;\n\n"
+ "export fn main() void = void: int as null: u16 is null;\n\n"
"export fn main() void = {\n\tyield void;\n}: int;\n");
};
diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha
@@ -527,7 +527,17 @@ fn cast(lexer: *lex::lexer, lvalue: (ast::expr | void)) (ast::expr | error) = {
yield ast::cast_kind::TEST;
case => abort();
};
- let typ = alloc(_type(lexer)?);
+ let typ = match (try(lexer, ltok::NULL)?) {
+ case let t: lex::token =>
+ yield alloc(ast::_type {
+ start = t.2,
+ end = lex::prevloc(lexer),
+ flags = 0,
+ repr = ast::builtin_type::NULL,
+ });
+ case void =>
+ yield alloc(_type(lexer)?);
+ };
return cast(lexer, ast::expr {
start = lvalue.start,
end = lex::prevloc(lexer),