Skip to content

Commit

Permalink
Fix recursive generic typed defs (#18809)
Browse files Browse the repository at this point in the history
  • Loading branch information
beef331 authored Sep 6, 2021
1 parent f373c17 commit 7ae52d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
cl.typeMap = newTypeMapLayer(cl)

for i in 1..<t.len:
var x = replaceTypeVarsT(cl, t[i])
var x = replaceTypeVarsT(cl, header[i])
assert x.kind != tyGenericInvocation
header[i] = x
propagateToOwner(header, x)
Expand Down
12 changes: 12 additions & 0 deletions tests/generics/trecursivegenerics.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
block: # Replicates #18728
type
FlipFlop[A, B] = ref object
next: FlipFlop[B, A]

Trinary[A, B, C] = ref object
next: Trinary[B, C, A]

assert typeof(FlipFlop[int, string]().next) is FlipFlop[string, int]
assert typeof(FlipFlop[string, int]().next) is FlipFlop[int, string]
assert typeof(Trinary[int, float, string]().next) is Trinary[float, string, int]
assert typeof(Trinary[int, float, string]().next.next) is Trinary[string, int, float]

0 comments on commit 7ae52d7

Please sign in to comment.