Skip to content

Commit da325b0

Browse files
beef331narimiran
authored andcommitted
No longer segfault when using a typeclass with a self referencing type (#19467)
(cherry picked from commit 1830a3b)
1 parent 196e93f commit da325b0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

compiler/sigmatch.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,8 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
16881688
var aa = a
16891689
while aa.kind in {tyTypeDesc, tyGenericParam} and aa.len > 0:
16901690
aa = lastSon(aa)
1691-
if aa.kind == tyGenericParam:
1691+
if aa.kind in {tyGenericParam} + tyTypeClasses:
1692+
# If the constraint is a genericParam or typeClass this isGeneric
16921693
return isGeneric
16931694
result = typeRel(c, f.base, aa, flags)
16941695
if result > isGeneric: result = isGeneric

tests/generics/tgenerics_issues.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,3 +860,15 @@ type
860860

861861
var a: Tile3[int]
862862

863+
block: # Ensure no segfault from constraint
864+
type
865+
Regex[A: SomeOrdinal] = ref object
866+
val: Regex[A]
867+
MyConstraint = (seq or enum or set)
868+
MyOtherType[A: MyConstraint] = ref object
869+
val: MyOtherType[A]
870+
871+
var
872+
a = Regex[int]()
873+
b = Regex[bool]()
874+
c = MyOtherType[seq[int]]()

0 commit comments

Comments
 (0)