Skip to content

Commit

Permalink
Fix #22826: Don't skip generic instances in type comparison (#22828)
Browse files Browse the repository at this point in the history
Close #22826

I am not sure why this code skips generic insts, so letting CI tell me.
Update: It has told me nothing. Maybe someone knows during review.

Issue itself seems to be that the generic instance is skipped thus it
ends up being just `float` which makes it use the wrong generic instance
of the proc because it matches the one in cache

---------

Co-authored-by: SirOlaf <>
(cherry picked from commit c13c485)
  • Loading branch information
SirOlaf authored and narimiran committed Apr 18, 2024
1 parent 106c7d2 commit 5e20e93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1210,12 +1210,12 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
if containsOrIncl(c, a, b): return true

if x == y: return true
var a = skipTypes(x, {tyGenericInst, tyAlias})
var a = skipTypes(x, {tyAlias})
while a.kind == tyUserTypeClass and tfResolved in a.flags:
a = skipTypes(a[^1], {tyGenericInst, tyAlias})
var b = skipTypes(y, {tyGenericInst, tyAlias})
a = skipTypes(a[^1], {tyAlias})
var b = skipTypes(y, {tyAlias})
while b.kind == tyUserTypeClass and tfResolved in b.flags:
b = skipTypes(b[^1], {tyGenericInst, tyAlias})
b = skipTypes(b[^1], {tyAlias})
assert(a != nil)
assert(b != nil)
if a.kind != b.kind:
Expand Down
8 changes: 8 additions & 0 deletions tests/generics/t22826.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import std/tables

var a: Table[string, float]

type Value*[T] = object
table: Table[string, Value[T]]

discard toTable({"a": Value[float]()})

0 comments on commit 5e20e93

Please sign in to comment.