-
-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempts to fix issue #266 #317
base: master
Are you sure you want to change the base?
Changes from 6 commits
1e1e6ab
532bc4f
8be203a
546a877
e17eb7c
c2d812b
9ea9fb3
6a7536a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -658,6 +658,8 @@ class parser { | |
return this->parse_expression(precedence{}); | ||
} | ||
|
||
static bool has_potential_side_effects(expression *ast); | ||
|
||
private: | ||
enum class variable_context { | ||
lhs, | ||
|
@@ -2515,8 +2517,43 @@ class parser { | |
} | ||
|
||
if (this->peek().type == token_type::kw_else) { | ||
source_code_span else_span = this->peek().span(); | ||
this->skip(); | ||
parse_and_visit_body(); | ||
|
||
switch (this->peek().type) { | ||
default: | ||
parse_and_visit_body(); | ||
break; | ||
|
||
case token_type::left_paren: | ||
strager marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expression *ast = this->parse_expression(precedence{}); | ||
this->visit_expression(ast, v, variable_context::rhs); | ||
|
||
bool is_invalidating_if = false; | ||
|
||
switch (ast->kind()) { | ||
default: | ||
break; | ||
|
||
case expression_kind::arrow_function_with_expression: | ||
case expression_kind::arrow_function_with_statements: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should make |
||
is_invalidating_if = true; | ||
break; | ||
} | ||
|
||
this->consume_semicolon(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking: This looks like it's in the wrong spot. Won't skipping a semicolon here cause the following code to have the error_else_with_conditional_missing_if warning? if (a) { b; } else (c);
{ d; } I think we need to consume a semicolon after the check on line 2546. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test for this example. |
||
|
||
if (this->peek().type == token_type::left_curly) { | ||
strager marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!is_invalidating_if && !this->has_potential_side_effects(ast)) { | ||
this->error_reporter_->report( | ||
error_else_with_conditional_missing_if{ | ||
.else_token = else_span, | ||
}); | ||
} | ||
parse_and_visit_body(); | ||
} | ||
break; | ||
strager marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we check
entry.value
regardless ofentry.property.has_value()
?