E02060: duplicated enumerated value in switch 'case'
What went wrong
The same enumeration value appears in multiple 'case' clauses of a switch. Each value can only be handled by one case.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 99 (How do I create an enumeration in EK9?)
How to fix it
- Remove the duplicate case
- Use comma-separated values for shared handling: case Red, Green
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E02060: duplicated enumerated value in switch 'case'
#!ek9 defines module error.e02060.bad defines type Direction North South East West defines function describe() -> direction as Direction <- rtn as String? switch direction case Direction.North rtn: "Going North" case Direction.South, Direction.East rtn: "Going South or East" case Direction.West rtn: "Going West" case Direction.North rtn: "North again" case Direction.East rtn: "East is already in the combined case above" default rtn: "Unknown"
Fixed: Each enumerated value in exactly one case; every value covered, and a default
#!ek9 defines module error.e02060.good defines type Direction North South East West defines function describe() -> direction as Direction <- rtn as String? switch direction case Direction.North rtn: "Going North" case Direction.South, Direction.East rtn: "Going South or East" case Direction.West rtn: "Going West" default rtn: "Unknown"
Questions and answers
These Q&A entries show E02060 and its fix:
Found a problem?
If EK9 reported E02060 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.