-
-
Notifications
You must be signed in to change notification settings - Fork 632
fix(semantic): consider update expressions in implicit returns as reads #5158
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
Changes from all commits
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 |
---|---|---|
|
@@ -355,3 +355,51 @@ fn test_ts_interface_heritage() { | |
.has_number_of_references(1) | ||
.test(); | ||
} | ||
|
||
#[test] | ||
fn test_arrow_implicit_return() { | ||
SemanticTester::js("let i = 0; const x = () => i") | ||
.has_root_symbol("i") | ||
.has_number_of_reads(1) | ||
.has_number_of_writes(0) | ||
.test(); | ||
|
||
SemanticTester::js("let i = 0; const x = () => ++i") | ||
.has_root_symbol("i") | ||
.has_number_of_reads(1) | ||
.has_number_of_writes(1) | ||
.test(); | ||
|
||
SemanticTester::js("let i = 0; const x = () => { ++i }") | ||
.has_root_symbol("i") | ||
.has_number_of_reads(0) | ||
.has_number_of_writes(1) | ||
.test(); | ||
|
||
SemanticTester::js("let i = 0; const x = () => (0, ++i)") | ||
.has_root_symbol("i") | ||
.has_number_of_reads(1) | ||
.has_number_of_writes(1) | ||
.test(); | ||
|
||
SemanticTester::js("let i = 0; const x = () => (++i, 0)") | ||
.has_root_symbol("i") | ||
.has_number_of_reads(1) | ||
.has_number_of_writes(1) | ||
.test(); | ||
Comment on lines
+385
to
+389
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. Is this test correct? I don't think 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. TBH, I am not sure what 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. Let's try to get to the bottom of it! #5165 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. IMO it's not, but there are other test cases that enforce this behavior. I mentioned this to you (@Dunqing) a while ago, when you made that change, and your rationale was that "we don't know what's a read and what's not a read, since things could be proxies and/or getters/setters" |
||
} | ||
|
||
#[test] | ||
fn test_arrow_explicit_return() { | ||
SemanticTester::js("let i = 0; const x = () => { return i }") | ||
.has_root_symbol("i") | ||
.has_number_of_reads(1) | ||
.has_number_of_writes(0) | ||
.test(); | ||
|
||
SemanticTester::js("let i = 0; const x = () => { return ++i }") | ||
.has_root_symbol("i") | ||
.has_number_of_reads(1) | ||
.has_number_of_writes(1) | ||
.test(); | ||
} |
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.
This may cause a bit of difficulty in maintaining. We should avoid writing any logic in the visit function.