From ee4a219012ca1fcb2cfb2cce4e87ff6774009d86 Mon Sep 17 00:00:00 2001 From: SirOlaf <34164198+SirOlaf@users.noreply.github.com> Date: Thu, 7 Sep 2023 05:46:45 +0200 Subject: [PATCH] Fix #17509: Continue instead of return with unfinished generics (#22563) Close #17509 Current knowledge: - delaying cache fixes the issue - changing return of `if inst.len < key.len:` in `searchInstTypes` to `continue` fixes the issue. With return the broken types are also cached over and over Related issues are completely unaffected as of now, so there must be something deeper. I am also still trying to find the true cause, so feel free to ignore for now --------- Co-authored-by: SirOlaf <> --- compiler/semtypinst.nim | 3 ++- tests/generics/t17509.nim | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/generics/t17509.nim diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index bd2b25c24e..4ab0e2de10 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -45,7 +45,8 @@ proc searchInstTypes*(g: ModuleGraph; key: PType): PType = # XXX: This happens for prematurely cached # types such as Channel[empty]. Why? # See the notes for PActor in handleGenericInvocation - return + # if this is return the same type gets cached more than it needs to + continue if not sameFlags(inst, key): continue diff --git a/tests/generics/t17509.nim b/tests/generics/t17509.nim new file mode 100644 index 0000000000..89f507577d --- /dev/null +++ b/tests/generics/t17509.nim @@ -0,0 +1,25 @@ +type List[O] = object + next: ptr List[O] + +proc initList[O](l: ptr List[O]) = + l[].next = l + +type + PolytopeVertex[R] = object + list: List[PolytopeVertex[R]] + + PolytopeEdge[R] = object + list: List[PolytopeEdge[R]] + + Polytope[R] = object + vertices: List[PolytopeVertex[R]] + edges: List[PolytopeEdge[R]] + +var pt: Polytope[float] + +static: + doAssert pt.vertices.next is (ptr List[PolytopeVertex[float]]) + doAssert pt.edges.next is (ptr List[PolytopeEdge[float]]) + +initList(addr pt.vertices) +initList(addr pt.edges) \ No newline at end of file