Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer segfault when using a typeclass with a self referencing type #19467

Merged
merged 1 commit into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]]()