Skip to content

Commit 86bfe85

Browse files
committed
Fix removing parentheses when using deducing assignement
The issue is caused by `emit(expression_list_node)` that skips parentheses when node is inside initializer - that serves cases like: ```cpp v : std::vector<int> = (1,2,3); ``` Where it generates: ```cpp std::vector<int> v{1,2,3}; ``` When `:=` is used in the following cases: ```cpp d := (1 + 2) * (3 + 4) * (5 + 6); ``` It removes first parentheses and we end up with: ```cpp auto d = {1 + 2 * (3 + 4) * ( 5 + 6)}; ``` This change corrects this behaviour on the parsing side it checks if it is initializer with a explicit type or is the type deduced (it is done by checking if before `Assignement` there is a `Colon`). ```cpp bool inside_initializer = ( peek(-1) && peek(-1)->type() == lexeme::Assignment && peek(-2) && peek(-2)->type() != lexeme::Colon ); ```
1 parent 827ed79 commit 86bfe85

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

source/parse.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2724,7 +2724,10 @@ class parser
27242724
// || curr().type() == lexeme::LeftBrace
27252725
)
27262726
{
2727-
bool inside_initializer = (peek(-1)->type() == lexeme::Assignment);
2727+
bool inside_initializer = (
2728+
peek(-1) && peek(-1)->type() == lexeme::Assignment
2729+
&& peek(-2) && peek(-2)->type() != lexeme::Colon
2730+
);
27282731
auto open_paren = &curr();
27292732
auto close = close_paren_type(open_paren->type());
27302733
auto close_text = [&] () -> std::string { if (close == lexeme::RightParen) { return ")"; } return "}"; }();

0 commit comments

Comments
 (0)