diff options
author | Jason Beetham <beefers331@gmail.com> | 2022-02-02 01:38:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 09:38:21 +0100 |
commit | 1830a3b505c33be5fc3b9e311c5e7720d9b37b32 (patch) | |
tree | 1bd1d71b47806886d2d0d832a16f05f7446c94d1 | |
parent | 22ae0bef63189dff28676b0dd5f6089864151120 (diff) | |
download | Nim-1830a3b505c33be5fc3b9e311c5e7720d9b37b32.tar.gz |
No longer segfault when using a typeclass with a self referencing type (#19467)
-rw-r--r-- | compiler/sigmatch.nim | 3 | ||||
-rw-r--r-- | tests/generics/tgenerics_issues.nim | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index e1195d04a..14f4c5e19 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -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 diff --git a/tests/generics/tgenerics_issues.nim b/tests/generics/tgenerics_issues.nim index 092926c01..db7a16569 100644 --- a/tests/generics/tgenerics_issues.nim +++ b/tests/generics/tgenerics_issues.nim @@ -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]]() |