Smarter variant object construction (#11273)
This commit is contained in:
parent
16aa10dfe1
commit
f774426095
9 changed files with 333 additions and 15 deletions
17
tests/objvariant/trt_discrim_err1.nim
Normal file
17
tests/objvariant/trt_discrim_err1.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
discard """
|
||||
errormsg: "branch initialization with a runtime discriminator is not supported inside of an `elif` branch."
|
||||
line: 16
|
||||
"""
|
||||
type
|
||||
Color = enum Red, Green, Blue
|
||||
ColorObj = object
|
||||
case colorKind: Color
|
||||
of Red: red: string
|
||||
of Green: green: string
|
||||
of Blue: blue: string
|
||||
|
||||
let colorKind = Blue
|
||||
case colorKind
|
||||
of Red: echo ColorObj(colorKind: colorKind, red: "red")
|
||||
elif colorKind == Green: echo ColorObj(colorKind: colorKind, green: "green")
|
||||
else: echo ColorObj(colorKind: colorKind, blue: "blue")
|
||||
Loading…
Add table
Add a link
Reference in a new issue