From e28d2f42e9ef38e5b984608d86b0d37833d118d0 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 19 Nov 2024 12:06:41 +0300 Subject: [PATCH] include new concepts in typeclasses, makes containsGenericType work (#24453) fixes #24450 The new concepts were previously not included in [containsGenericType][1] which prevents them from being instantiated. Here they are included by being added to `tyTypeClasses` though this doesn't have to be done, they can also be added manually to `containsGenericTypeIter`, but this might be too specific. [1]: https://github.com/nim-lang/Nim/blob/a2031ec6cfe9475fb38ebc204ebcf8c2b6d02dce/compiler/types.nim#L1507-L1517 --- compiler/ast.nim | 2 +- compiler/typeallowed.nim | 3 --- tests/concepts/tuninstantiated.nim | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/concepts/tuninstantiated.nim diff --git a/compiler/ast.nim b/compiler/ast.nim index cc3f4dcd99..a187687f4e 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -279,7 +279,7 @@ const GcTypeKinds* = {tyRef, tySequence, tyString} tyTypeClasses* = {tyBuiltInTypeClass, tyCompositeTypeClass, - tyUserTypeClass, tyUserTypeClassInst, + tyUserTypeClass, tyUserTypeClassInst, tyConcept, tyAnd, tyOr, tyNot, tyAnything} tyMetaTypes* = {tyGenericParam, tyTypeDesc, tyUntyped} + tyTypeClasses diff --git a/compiler/typeallowed.nim b/compiler/typeallowed.nim index 39193a42da..a814597e27 100644 --- a/compiler/typeallowed.nim +++ b/compiler/typeallowed.nim @@ -209,9 +209,6 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, result = typeAllowedAux(marker, t.skipModifier, kind, c, flags+{taHeap}) else: result = t - of tyConcept: - if kind != skParam: result = t - else: result = nil proc typeAllowed*(t: PType, kind: TSymKind; c: PContext; flags: TTypeAllowedFlags = {}): PType = # returns 'nil' on success and otherwise the part of the type that is diff --git a/tests/concepts/tuninstantiated.nim b/tests/concepts/tuninstantiated.nim new file mode 100644 index 0000000000..2574cce25e --- /dev/null +++ b/tests/concepts/tuninstantiated.nim @@ -0,0 +1,17 @@ +block: # issue #24450 + type + B = object + b: int + A = object + x: int + AConcept = concept + proc implementation(s: var Self, p1: B) + + proc implementation(r: var A, p1: B)= + discard + + proc accept(r: var AConcept)= + discard + + var a = A() + a.accept()