diff options
| author | Mel <mel@rnrd.eu> | 2025-06-15 04:57:10 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-06-15 04:57:10 +0200 |
| commit | a63977f56a4c3dc4c53f0befe65c8252cc5c9b0b (patch) | |
| tree | ba2d0347b71f218514ecb9dbe05d19632b4b79c5 | |
| parent | bf5348ece49e615cc9867d8eed444c0efc11e586 (diff) | |
| download | catskill-a63977f56a4c3dc4c53f0befe65c8252cc5c9b0b.tar.zst catskill-a63977f56a4c3dc4c53f0befe65c8252cc5c9b0b.zip | |
Fix disambiguation check between no-return function body & function returning inline struct
Signed-off-by: Mel <mel@rnrd.eu>
| -rw-r--r-- | boot/parse.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/boot/parse.c b/boot/parse.c index 490995f..3d2706f 100644 --- a/boot/parse.c +++ b/boot/parse.c @@ -268,15 +268,17 @@ parser_function_header_node(struct Parser* p, struct Parser_Error* error) struct Token next = parser_peek(p); struct Token further = parser_peek_further(p); - // NOTE: this is very uncomfortable. to avoid ambiguity between a no-return-type function body - // (i.e. `fun () {`) and a function with a return type of inline - // structure (i.e. `fun () {x int} {`), we require that inline structs are declared in one line, - // without a line-break, and function bodies always have a line-break after the opening brace. - // this means that we cannot have a single line function, and we can't have a function with an - // inline structure as a return type that is too long to fit on a single line. - // TODO: to allow single line functions, introduce a `:` token as a replacement for the - // opening brace. `fun (x int): x + 1` - if (token_can_begin_type(&next) && !token_is(&further, TOKEN_NEWLINE)) { + if (token_can_begin_type(&next)) { + // NOTE: this is very uncomfortable. to avoid ambiguity between a no-return-type function + // body (i.e. `fun () {`) and a function with a return type of inline structure (i.e. `fun + // () {x int} {`), we require that inline structs are declared in one line, without a + // line-break, and function bodies always have a line-break after the opening brace. this + // means that we cannot have a single line function, and we can't have a function with an + // inline structure as a return type that is too long to fit on a single line. + // TODO: to allow single line functions, introduce a `:` token as a replacement for the + // opening brace. `fun (x int): x + 1` + if (token_is(&next, TOKEN_CURLY_OPEN) && token_is(&further, TOKEN_NEWLINE)) return header; + header.return_type = CHECK_RETURN(parser_node_type(p, error), struct Function_Header_Node); header.span = span_merge(header.span, header.return_type->span); } |
