Skip to content

Commit

Permalink
Fix #17509: Continue instead of return with unfinished generics (#22563)
Browse files Browse the repository at this point in the history
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 <>
  • Loading branch information
SirOlaf committed Sep 7, 2023
1 parent a4df44d commit ee4a219
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions tests/generics/t17509.nim
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit ee4a219

Please sign in to comment.