From 5dcfd8d7bbe0d10769240fd790b693e112cc3a8d Mon Sep 17 00:00:00 2001 From: Ryan McConnell Date: Thu, 24 Apr 2025 15:17:42 -0400 Subject: [PATCH] Add `tySet` to concept matching (#24908) --- compiler/concepts.nim | 4 ++++ tests/concepts/tconceptsv2.nim | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/compiler/concepts.nim b/compiler/concepts.nim index 1c8860bd5f..7c64b5eae9 100644 --- a/compiler/concepts.nim +++ b/compiler/concepts.nim @@ -419,6 +419,10 @@ proc matchType(c: PContext; fo, ao: PType; m: var MatchCon): bool = result = matchType(c, ff, a, m) if result: break # and remember the binding! m.bindings.setToPreviousLayer() + of tySet: + result = false + if a.kind == tySet: + result = matchType(c, f.elementType, a.elementType, m) else: result = false if result and ao.kind == tyGenericParam: diff --git a/tests/concepts/tconceptsv2.nim b/tests/concepts/tconceptsv2.nim index 83a19348b1..369fd3e854 100644 --- a/tests/concepts/tconceptsv2.nim +++ b/tests/concepts/tconceptsv2.nim @@ -485,6 +485,18 @@ block: assert Container[AsyncImpl] isnot SyncType assert Container[AsyncImpl] is AsyncType +block: + type + C1 = concept + proc p(x: typedesc[Self]): int + E1 = enum + One, Two + proc p[E: enum](x: typedesc[set[E]]): int = sizeof(set[E]) + + proc spring(x: C1) = discard + + spring({One,Two}) + # this code fails inside a block for some reason type Indexable[T] = concept proc `[]`(t: Self, i: int): T