Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/guards.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ proc isLocation(n: PNode): bool = not n.isValue

proc isLet(n: PNode): bool =
if n.kind == nkSym:
if n.sym.kind in {skLet, skTemp, skForVar}:
if n.sym.kind in {skLet, skConst, skTemp, skForVar}: # guard immutable variables
result = true
elif n.sym.kind == skParam and skipTypes(n.sym.typ,
abstractInst).kind notin {tyVar}:
Expand Down
22 changes: 22 additions & 0 deletions tests/objvariant/tcorrectcheckedfield.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,25 @@ block: # issue #24021
discard
else:
discard foo.z


# bug #22791
type Foo = object
case a: bool
of false:
discard
of true:
case b: bool
of false:
discard
of true:
c: bool

const f = Foo(a: true, b: true, c: true)
case f.a
of true:
case f.b
of true:
echo f.c
Comment thread
ringabout marked this conversation as resolved.
else: discard
else: discard