From bc3e964e9d1e15e5e2d72abded90c5ebc50d649a Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 6 Dec 2022 00:52:49 +0300 Subject: [PATCH] fix #16639 (#21017) (cherry picked from commit e98efdcc5eb5679fed5540a0a7c5a12e5d23f826) --- compiler/semtypes.nim | 7 ++++--- tests/generics/t16639.nim | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/generics/t16639.nim diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 31aae6e6f7..eac93044ac 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -754,9 +754,10 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int, if n == nil: return case n.kind of nkRecWhen: + var a = copyTree(n) var branch: PNode = nil # the branch to take - for i in 0.. 0: - father.add n + father.add a elif branch != nil: semRecordNodeAux(c, branch, check, pos, father, rectype, hasCaseFields) elif father.kind in {nkElse, nkOfBranch}: diff --git a/tests/generics/t16639.nim b/tests/generics/t16639.nim new file mode 100644 index 0000000000..52d7e13d0e --- /dev/null +++ b/tests/generics/t16639.nim @@ -0,0 +1,20 @@ +discard """ + action: compile +""" + +type Foo[T] = object + when true: + x: float + +type Bar = object + when true: + x: float + +import std/macros + +macro test() = + let a = getImpl(bindSym"Foo")[^1] + let b = getImpl(bindSym"Bar")[^1] + doAssert treeRepr(a) == treeRepr(b) + +test()