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

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]>
@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.68%. Comparing base (5bdb746) to head (3a20047).

Files with missing lines Patch % Lines
pkg/compiler/codegen.go 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4078      +/-   ##
==========================================
- Coverage   83.51%   82.68%   -0.83%     
==========================================
  Files         351      351              
  Lines       42404    42422      +18     
==========================================
- Hits        35412    35075     -337     
- Misses       5249     5269      +20     
- Partials     1743     2078     +335     

☔ 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.


last := len(n.Body.List) - 1
for i := range n.Body.List {
if i < last && len(n.Body.List[i].(*ast.CaseClause).List) == 0 { // early default
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's better not to call the len function, but just look at the equality of n.Body.List[i].(*ast.CaseClause).List == nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right. But 1st, @Turalchik do u rly think modifying the original slice is safe enough solution?

c.pushStackLabel(label, 1)

last := len(n.Body.List) - 1
for i := range n.Body.List {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use for i := range last {...}, then you won't have to check the condition i < last.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants