Is there a way to make an enum/set/range type be a subset of another enum type? For instance, in the following code, func1 and func2 return two of the three possible enum values of ReturnType while func3 calls both function and can return any one of the 3 possible enum values.
type
ReturnType* = enum
NoError
TooFlat
TooTall
proc func1(x: string): range[NoError..TooFlat] =
if x == "pancake": TooFlat
else: NoError
proc func2(x: string): {NoError, TooTall} =
# ^---------- this is what I want to write
if x == "tree": TooTall
else: NoError
proc func3(x: string): ReturnType =
case func1(x)
of TooFlat: return TooFlat
of NoError:
case func2(x)
of TooTall: return TooTall
of NoError: return NoError
Using range is the closest I can get, but I can only range contiguous spans of the enum values. I don't have to use enums. I just want to be able to use case statements to make sure I've covered all possible cases.