www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22708] New: switch statement with an undefined symbol results

https://issues.dlang.org/show_bug.cgi?id=22708

          Issue ID: 22708
           Summary: switch statement with an undefined symbol results in
                    many errors
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: schveiguy gmail.com

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.

--
Jan 27 2022