fixes a strict case object problem that has been reported on the forum (#20614)

This commit is contained in:
Andreas Rumpf 2022-10-21 22:46:32 +02:00 • committed by GitHub
commit 0faae4d5e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View file

@ -1,10 +1,30 @@
discard """
errormsg: "field access outside of valid case branch: x.x"
line: 25
line: 45
"""
{.experimental: "strictCaseObjects".}
type
NodeKind = enum
nkParent,
nkChild
Node {.acyclic.} = ref object
case kind: NodeKind
of nkParent:
children: seq[Node]
of nkChild:
name: string
let list = @[Node(kind: nkParent, children: @[]), Node(kind: nkChild, name: "hello")]
for node in list:
case node.kind
of nkChild:
echo $node.name # here this time there is a warning
else: discard
type
Foo = object
case b: bool