argotorg / argotorg/solidity

Disallow `switch` with only `default` case in Yul

Open
#16,165 0 comments 0 reactions 0 assignees View on GitHub
breaking change :warning: low effort low impact should have
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

### Abstract
A `switch` where the only case is `default` is redundant and equivalent to a block. It should produce an error.

### Motivation
This has been marked as deprecated when we rewrote the grammar definitions in #9606: https://github.com/ethereum/solidity/blob/73712a01b2de56d9ad91e3b6936f85c90cb7de36/docs/grammar/SolidityParser.g4#L593-L597

The compiler already issues a warning about this:
```yul
{
switch true
default {}
}
```
```
Warning: "switch" statement with only a default case.
```

The change is breaking, so we could not turn this into an error earlier. 0.9.0 is on the horizon and would be a good moment.

Contributor guide

Open the contributing guide

Research direction

Read docs/grammar/SolidityParser.g4 around the deprecated switch grammar referenced in the issue, then trace the compiler's existing warning for a switch with only a default case. Done means this Yul construct is rejected as an error rather than accepted with a warning, with coverage for the shown example.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.