about summary refs log tree commit diff
path: root/boot
diff options
context:
space:
mode:
Diffstat (limited to 'boot')
-rw-r--r--boot/parse.c20
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);
     }