-
Notifications
You must be signed in to change notification settings - Fork 100
compiler: Fix expression switch with non-last default
#4078
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4078 +/- ##
==========================================
- Coverage 83.51% 83.47% -0.04%
==========================================
Files 351 351
Lines 42404 42395 -9
==========================================
- Hits 35412 35389 -23
- Misses 5249 5275 +26
+ Partials 1743 1731 -12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
According to https://go.dev/ref/spec#Expression_switches: > There can be at most one default case and it may appear anywhere in the "switch" statement. Previously, `default` statements executed even if they are followed by a matching `case`. Signed-off-by: Leonard Lyubich <[email protected]>
3a20047 to
04ba0e2
Compare
AnnaShaleva
left a comment
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.
Other than that LGTM.
| last := len(n.Body.List) - 1 | ||
| for i := range last { | ||
| if n.Body.List[i].(*ast.CaseClause).List == nil { // early default | ||
| n.Body.List[i], n.Body.List[last] = n.Body.List[last], n.Body.List[i] |
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.
We need to check if this substitution affects generated debug info. Lines info stored in debug info for substituted default should match the source code.
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.
how can i check this?
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.
See how saveSequencePoint works, ensure that proper statement boundaries will be stored in the debug info file on compilation:
Line 128 in 93fe450
| func (c *codegen) saveSequencePoint(n ast.Node) { |
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.
@cthulhu-rider ping.
Problem
i encountered this once while debugging a contract and spent a lot of time searching for the problem
Solution
first, swapping expressions as the most obvious. But it changes the input, and mutation is possible. Cloning is an option, but im gonna think about it some more