From 71402c3aa7a61fdacb82922d0811a9d705d284fc Mon Sep 17 00:00:00 2001 From: Ryan McConnell Date: Wed, 27 Nov 2024 00:15:18 -0500 Subject: [PATCH] compsite typclass --- compiler/concepts.nim | 3 ++- tests/concepts/tconceptsv2.nim | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/compiler/concepts.nim b/compiler/concepts.nim index 8c52909fbbd8..b063a764fd00 100644 --- a/compiler/concepts.nim +++ b/compiler/concepts.nim @@ -187,7 +187,8 @@ proc matchType(c: PContext; f, a: PType; m: var MatchCon): bool = ak = last(a) result = matchType(c, last(f), ak, m) of tyCompositeTypeClass: - result = matchType(c, last(f), a, m) + var ak = if a.kind == tyCompositeTypeClass: a.last else: a + result = matchType(c, last(f), ak, m) of tyArray, tyTuple, tyVarargs, tyOpenArray, tyRange, tySequence, tyRef, tyPtr, tyGenericInst: # ^ XXX Rewrite this logic, it's more complex than it needs to be. diff --git a/tests/concepts/tconceptsv2.nim b/tests/concepts/tconceptsv2.nim index 5934ec439e49..178e58aac162 100644 --- a/tests/concepts/tconceptsv2.nim +++ b/tests/concepts/tconceptsv2.nim @@ -77,3 +77,17 @@ block: proc p(a: Buffer)=discard var buffer = ArrayBuffer[5]() p(buffer) + +block: # composite typeclass matching + type + A[T] = object + Buffer = concept + proc put(s: Self, i: A) + BufferImpl = object + WritableImpl = object + + proc launch(a: var Buffer)=discard + proc put(x: BufferImpl, i: A)=discard + + var a = BufferImpl() + launch(a)