Skip to content

Commit

Permalink
fix #16639 (#21017)
Browse files Browse the repository at this point in the history
(cherry picked from commit e98efdc)
  • Loading branch information
metagn authored and narimiran committed May 12, 2023
1 parent c641273 commit 746b576
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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..<n.len:
var it = n[i]
for i in 0..<a.len:
var it = a[i]
if it == nil: illFormedAst(n, c.config)
var idx = 1
case it.kind
Expand All @@ -782,7 +783,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
semRecordNodeAux(c, it[idx], newCheck, newPos, newf, rectype, hasCaseFields)
it[idx] = if newf.len == 1: newf[0] else: newf
if c.inGenericContext > 0:
father.add n
father.add a
elif branch != nil:
semRecordNodeAux(c, branch, check, pos, father, rectype, hasCaseFields)
elif father.kind in {nkElse, nkOfBranch}:
Expand Down
21 changes: 21 additions & 0 deletions tests/generics/t16639.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
discard """
action: compile
"""

type Foo[T] = object
when true:
x: float

type Bar = object
when true:
x: float

import std/macros
import std/assertions

macro test() =
let a = getImpl(bindSym"Foo")[^1]
let b = getImpl(bindSym"Bar")[^1]
doAssert treeRepr(a) == treeRepr(b)

test()

0 comments on commit 746b576

Please sign in to comment.