From 5e20e935ddb58bc10bcdddd92555c16743e35ce5 Mon Sep 17 00:00:00 2001 From: SirOlaf <34164198+SirOlaf@users.noreply.github.com> Date: Sat, 21 Oct 2023 22:00:16 +0200 Subject: [PATCH] Fix #22826: Don't skip generic instances in type comparison (#22828) 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 c13c48500b527cb483480702390b1f230ac896a4) --- compiler/types.nim | 8 ++++---- tests/generics/t22826.nim | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 tests/generics/t22826.nim diff --git a/compiler/types.nim b/compiler/types.nim index 3d620b1f6ff18..45cb52ce5a04a 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -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: diff --git a/tests/generics/t22826.nim b/tests/generics/t22826.nim new file mode 100644 index 0000000000000..914d4243a2de3 --- /dev/null +++ b/tests/generics/t22826.nim @@ -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]()}) \ No newline at end of file