E07630: operator cannot be used on an Enumeration in this way
What went wrong
An operator (or method) is applied to the ENUMERATION TYPE itself, for example '$CardSuit' or 'CardSuit > CardSuit.Hearts'. The type is not a value: operators apply to the enumeration's values, such as 'CardSuit.Hearts' or a variable that holds one.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 99 (How do I create an enumeration in EK9?)
What works on a value
An enumeration's values are ordered (in declaration order), so the comparison operators (<, <=, >, >=, ==, <>, <=>) work on them, as do '$' (the name of the value), '?', '#?' and '#<' / '#>' (the first and last value). Iterate the type itself with 'for suit in CardSuit' or 'cat CardSuit'.
How to fix it
- Apply the operator to a value: CardSuit.Hearts, or a variable holding one
- To visit every value, iterate the type: for suit in CardSuit
Common causes
- Writing the type name where a value was meant
- Expecting '$' on the type to list its values
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07630: operator cannot be used on an Enumeration in this way
#!ek9 defines module error.e07630.bad defines type CardSuit Hearts Diamonds Clubs Spades defines function describeSuits() stdout <- Stdout() //CardSuit is the type; '$' applies to one of its values stdout.println($CardSuit)
Fixed: Apply the operator to a value of the enumeration
#!ek9 defines module error.e07630.good defines type CardSuit Hearts Diamonds Clubs Spades defines program DescribeSuits() stdout <- Stdout() //Every value of the enumeration, in order for suit in CardSuit stdout.println($suit) //Operators apply to values, and the values are ordered hearts <- CardSuit.Hearts stdout.println($hearts) stdout.println($(hearts < CardSuit.Spades))
Questions and answers
These Q&A entries show E07630 and its fix: