Skip to content

Commit 19132f1

Browse files
authored
Correction for short function syntax, closes #356 (#359)
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
1 parent d7adb8f commit 19132f1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

source/parse.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,17 @@ class parser
30153015
next();
30163016
return {};
30173017
}
3018+
if (
3019+
peek(-1) && peek(-1)->type() != lexeme::RightBrace // it is short function syntax
3020+
&& curr().type() != lexeme::LeftParen // not imediatelly called
3021+
&& curr().type() != lexeme::RightParen // not as a last argument to function
3022+
&& curr().type() != lexeme::Comma // not as first or in-the-middle, function argument
3023+
) {
3024+
// this is a fix for a short function syntax that should have double semicolon used
3025+
// (check comment in expression_statement(bool semicolon_required))
3026+
// We simulate double semicolon by moving back to single semicolon.
3027+
next(-1);
3028+
}
30183029
}
30193030
else {
30203031
error("(temporary alpha limitation) an unnamed declaration at expression scope must be a function or an object");

0 commit comments

Comments
 (0)