Skip to content

Conversation

@cthulhu-rider
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.47%. Comparing base (5bdb746) to head (04ba0e2).
⚠️ Report is 30 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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]>
@cthulhu-rider cthulhu-rider force-pushed the compiler-switch-non-last-default branch from 3a20047 to 04ba0e2 Compare December 1, 2025 11:54
@cthulhu-rider cthulhu-rider marked this pull request as ready for review December 1, 2025 11:55
Copy link
Member

@AnnaShaleva AnnaShaleva left a 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]
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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:

func (c *codegen) saveSequencePoint(n ast.Node) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnnaShaleva AnnaShaleva added bug Something isn't working compiler Go smart contract compiler labels Dec 3, 2025
@AnnaShaleva AnnaShaleva added this to the v0.115.0 milestone Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compiler Go smart contract compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants