fixes a strict case object problem that has been reported on the forum (#20614)
This commit is contained in:
parent
3c12b72168
commit
0faae4d5e2
2 changed files with 25 additions and 2 deletions
|
|
@ -68,9 +68,12 @@ proc isLetLocation(m: PNode, isApprox: bool): bool =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkDotExpr, nkCheckedFieldExpr, nkObjUpConv, nkObjDownConv:
|
of nkDotExpr, nkCheckedFieldExpr, nkObjUpConv, nkObjDownConv:
|
||||||
n = n[0]
|
n = n[0]
|
||||||
of nkDerefExpr, nkHiddenDeref:
|
of nkDerefExpr:
|
||||||
n = n[0]
|
n = n[0]
|
||||||
inc derefs
|
inc derefs
|
||||||
|
of nkHiddenDeref:
|
||||||
|
n = n[0]
|
||||||
|
if not isApprox: inc derefs
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
if isConstExpr(n[1]) or isLet(n[1]) or isConstExpr(n[1].skipConv):
|
if isConstExpr(n[1]) or isLet(n[1]) or isConstExpr(n[1].skipConv):
|
||||||
n = n[0]
|
n = n[0]
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,30 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "field access outside of valid case branch: x.x"
|
errormsg: "field access outside of valid case branch: x.x"
|
||||||
line: 25
|
line: 45
|
||||||
"""
|
"""
|
||||||
|
|
||||||
{.experimental: "strictCaseObjects".}
|
{.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
|
type
|
||||||
Foo = object
|
Foo = object
|
||||||
case b: bool
|
case b: bool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue