Bug 22708 – switch statement with an undefined symbol results in many errors
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-01-27T18:29:35Z
Last change time
2022-03-08T16:27:12Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Steven Schveighoffer
Comments
Comment #0 by schveiguy — 2022-01-27T18:29:35Z
Consider this code:
```d
enum Foo
{
one, two
}
void main()
{
final switch(foo()) { // oops, forgot to define foo()
case Foo.one: break;
case Foo.two: break;
}
}
```
In addition to the correct error of "foo" not being defined, the compiler will emit nonsense errors based on the case statements.
The error has changed throughout the years.
for 2.097, the error is:
Error: duplicate `case two` in `switch` statement
Note the missing "Foo." prefix, no error about case `Foo.one`, and also, the nonsensical error.
For 2.098.1, the error has changed to:
Error: `case` must be a `string` or an integral constant, not `one`
Error: `case` must be a `string` or an integral constant, not `two`
Such errors should either be omitted, or adjusted to be less confusing.
Comment #1 by dlang-bot — 2022-02-07T16:00:58Z
@MoonlightSentinel created dlang/dmd pull request #13617 "Fix 22708 - Extends semantic for switch statements with invalid values" fixing this issue:
- Fix 22708 - Extends semantic for switch statements with invalid values
Only omitting the cast allows further semantic to perform the expected
checks and transformations. This allows for better error detection that
were not reported before and also avoids invalid errors due to missing
`optimize` calls.
https://github.com/dlang/dmd/pull/13617
Comment #2 by dlang-bot — 2022-03-04T14:30:20Z
@Panke updated dlang/dmd pull request #13755 "Fix Issue 21844: makedeps contain non-existing files" fixing this issue:
- Fix 22708 - Extend semantic for switch statements with invalid values (#13617)
Only omitting the cast allows further semantic to perform the expected
checks and transformations. This allows for better error detection that
were not reported before and also avoids invalid errors due to missing
`optimize` calls.
https://github.com/dlang/dmd/pull/13755
Comment #3 by dlang-bot — 2022-03-08T15:05:54Z
@MartinNowak created dlang/dmd pull request #13785 "merge stable" fixing this issue:
- Fix 22708 - Extend semantic for switch statements with invalid values (#13617)
Only omitting the cast allows further semantic to perform the expected
checks and transformations. This allows for better error detection that
were not reported before and also avoids invalid errors due to missing
`optimize` calls.
https://github.com/dlang/dmd/pull/13785
Comment #4 by dlang-bot — 2022-03-08T16:27:12Z
dlang/dmd pull request #13785 "merge stable" was merged into master:
- 160e3ebeaed0448a81322b2c19a0ac156445d61e by Florian:
Fix 22708 - Extend semantic for switch statements with invalid values (#13617)
Only omitting the cast allows further semantic to perform the expected
checks and transformations. This allows for better error detection that
were not reported before and also avoids invalid errors due to missing
`optimize` calls.
https://github.com/dlang/dmd/pull/13785