From d737f9e6276bd02937a5b6672f03cfbeb931ce18 Mon Sep 17 00:00:00 2001 From: Filip Sajdak Date: Sun, 16 Apr 2023 01:58:03 +0200 Subject: [PATCH] Correction for short function syntax, closes #356 Current implementation does not work for the following code: ```cpp main: () = { :() = 1; [[assert: 1]] } ``` It fails with error: ``` error: subscript expression [ ] must not be empty (if you were trying to name a C-style array type, use 'std::array' instead) (at '[') ``` This change introduce small correction that moves back parsing to semicolon (to simulate double semicolon) for short syntax. It is not done in the following cases: ```cpp :() = 1;(); // imediatelly called lambda f(a,b,:() = 1;); // last argument in function call f(a,:() = 1;,c); // first or in the middle argument ``` After this change the original issue is solved. All regression tests pass. Closes #356 --- source/parse.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/parse.h b/source/parse.h index e868a06713..d25cc98bce 100644 --- a/source/parse.h +++ b/source/parse.h @@ -3015,6 +3015,17 @@ class parser next(); return {}; } + if ( + peek(-1) && peek(-1)->type() != lexeme::RightBrace // it is short function syntax + && curr().type() != lexeme::LeftParen // not imediatelly called + && curr().type() != lexeme::RightParen // not as a last argument to function + && curr().type() != lexeme::Comma // not as first or in-the-middle, function argument + ) { + // this is a fix for a short function syntax that should have double semicolon used + // (check comment in expression_statement(bool semicolon_required)) + // We simulate double semicolon by moving back to single semicolon. + next(-1); + } } else { error("(temporary alpha limitation) an unnamed declaration at expression scope must be a function or an object");