type Foo = enum f0 f1
proc main()=
var f = f0
case f
of f0: echo "ok0"
of f1: echo "ok1"
when defined(case2_1):
of f2:
echo "ok2"
elif defined case2_2:
of f2b, f2c:
echo "ok2b"
elif defined case2_3:
else: # else is allowed too
echo "ok3"
main()
likewise with case objects:
type Foo = enum f0 f1
type Bar = object
case f: Foo
of f0: v0: int
of f1: v1: int
when not defined(js):
of f3: v3: int
implementation
inside a when statement (or elif branch following a when statement), a of or else shall be attached to preceding case statement.
I suspect this RFC is less impactful than https://github.com/nim-lang/RFCs/issues/190 in terms of making existing macros (macros manipulating case..of would now need to handle the case of when branches to be 100% correct, but these are likely less frequent than macros handling enum's)
proposal
allow
when
in case statementsexample
likewise with case objects:
implementation
inside a when statement (or elif branch following a when statement), a
of
orelse
shall be attached to preceding case statement.related