diff --git a/compiler/guards.nim b/compiler/guards.nim index 15922b3442..d51064ba8a 100644 --- a/compiler/guards.nim +++ b/compiler/guards.nim @@ -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}: diff --git a/tests/objvariant/tcorrectcheckedfield.nim b/tests/objvariant/tcorrectcheckedfield.nim index e5e67c727d..acb3acda14 100644 --- a/tests/objvariant/tcorrectcheckedfield.nim +++ b/tests/objvariant/tcorrectcheckedfield.nim @@ -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 + else: discard +else: discard \ No newline at end of file