diff --git a/compiler/semfold.nim b/compiler/semfold.nim index d59dacd9a084d..e94a15fbe75a7 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -719,6 +719,8 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode = result.typ = n.typ of nkBracketExpr: result = foldArrayAccess(m, n, g) of nkDotExpr: result = foldFieldAccess(m, n, g) + of nkCheckedFieldExpr: + result = foldFieldAccess(m, n[0], g) of nkStmtListExpr: var i = 0 while i <= n.len - 2: diff --git a/tests/arc/tcaseobj.nim b/tests/arc/tcaseobj.nim index 107cf9fc15d67..a967a509bc9b7 100644 --- a/tests/arc/tcaseobj.nim +++ b/tests/arc/tcaseobj.nim @@ -223,3 +223,24 @@ type MyObj = object var a = MyObj(kind: false, x0: 1234) a.kind = true doAssert(a.x1 == "") + +block: + # bug #15532 + type Kind = enum + k0, k1 + + type Foo = object + y: int + case kind: Kind + of k0: x0: int + of k1: x1: int + + const j0 = Foo(y: 1, kind: k0, x0: 2) + const j1 = Foo(y: 1, kind: k1, x1: 2) + + doAssert j0.y == 1 + doAssert j0.kind == k0 + doAssert j1.kind == k1 + + doAssert j1.x1 == 2 + doAssert j0.x0 == 2