Skip to content

Commit

Permalink
No longer segfault when using a typeclass with a self referencing type (
Browse files Browse the repository at this point in the history
  • Loading branch information
beef331 authored Feb 2, 2022
1 parent 22ae0be commit 1830a3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,8 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
var aa = a
while aa.kind in {tyTypeDesc, tyGenericParam} and aa.len > 0:
aa = lastSon(aa)
if aa.kind == tyGenericParam:
if aa.kind in {tyGenericParam} + tyTypeClasses:
# If the constraint is a genericParam or typeClass this isGeneric
return isGeneric
result = typeRel(c, f.base, aa, flags)
if result > isGeneric: result = isGeneric
Expand Down
12 changes: 12 additions & 0 deletions tests/generics/tgenerics_issues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -860,3 +860,15 @@ type

var a: Tile3[int]

block: # Ensure no segfault from constraint
type
Regex[A: SomeOrdinal] = ref object
val: Regex[A]
MyConstraint = (seq or enum or set)
MyOtherType[A: MyConstraint] = ref object
val: MyOtherType[A]

var
a = Regex[int]()
b = Regex[bool]()
c = MyOtherType[seq[int]]()

0 comments on commit 1830a3b

Please sign in to comment.