Skip to content

Commit 5dcfd8d

Browse files
authored
Add tySet to concept matching (#24908)
1 parent d966ee3 commit 5dcfd8d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler/concepts.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ proc matchType(c: PContext; fo, ao: PType; m: var MatchCon): bool =
419419
result = matchType(c, ff, a, m)
420420
if result: break # and remember the binding!
421421
m.bindings.setToPreviousLayer()
422+
of tySet:
423+
result = false
424+
if a.kind == tySet:
425+
result = matchType(c, f.elementType, a.elementType, m)
422426
else:
423427
result = false
424428
if result and ao.kind == tyGenericParam:

tests/concepts/tconceptsv2.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,18 @@ block:
485485
assert Container[AsyncImpl] isnot SyncType
486486
assert Container[AsyncImpl] is AsyncType
487487

488+
block:
489+
type
490+
C1 = concept
491+
proc p(x: typedesc[Self]): int
492+
E1 = enum
493+
One, Two
494+
proc p[E: enum](x: typedesc[set[E]]): int = sizeof(set[E])
495+
496+
proc spring(x: C1) = discard
497+
498+
spring({One,Two})
499+
488500
# this code fails inside a block for some reason
489501
type Indexable[T] = concept
490502
proc `[]`(t: Self, i: int): T

0 commit comments

Comments
 (0)