Skip to content

Commit

Permalink
fixes #15532 (#15534)
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq authored Oct 9, 2020
1 parent 16e8005 commit d430216
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/semfold.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions tests/arc/tcaseobj.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 comment on commit d430216

@timotheecour
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the quick fix!

Please sign in to comment.