From ee44fe197b996780aa2ab7dd80fc866d13be258e Mon Sep 17 00:00:00 2001 From: Ryan McConnell Date: Fri, 11 Apr 2025 00:54:52 -0400 Subject: [PATCH] new-style concept bugfix (#24858) Combining two small PRs in one here. The test case explains what was wrong with the concepts and for naitivesockets, it's typical to adjust `ai_flags` so I opened that up. (cherry picked from commit d4098e6ca031aba9825980f9a17d3b54a9990577) --- compiler/concepts.nim | 3 ++- tests/concepts/tconceptsv2.nim | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/compiler/concepts.nim b/compiler/concepts.nim index b18956c3b0..1c8860bd5f 100644 --- a/compiler/concepts.nim +++ b/compiler/concepts.nim @@ -347,10 +347,11 @@ proc matchType(c: PContext; fo, ao: PType; m: var MatchCon): bool = k1 = f.kidsLen - ord(f.kind == tyGenericInst) k2 = ea.kidsLen - ord(ea.kind == tyGenericInst) if sameType(f.genericHead, ea.genericHead) and k1 == k2: + result = true for i in 1 ..< k2: if not matchType(c, f[i], ea[i], m): + result = false break - result = true of tyOrdinal: result = isOrdinalType(a, allowEnumWithHoles = false) or a.kind == tyGenericParam of tyStatic: diff --git a/tests/concepts/tconceptsv2.nim b/tests/concepts/tconceptsv2.nim index afa66eda33..83a19348b1 100644 --- a/tests/concepts/tconceptsv2.nim +++ b/tests/concepts/tconceptsv2.nim @@ -459,6 +459,32 @@ block: var s = ArrayBuffer[1500]() spring(s, 8.uint8) +block: + type + Future[T] = object + SyncType = concept + proc p(s: Self) + AsyncType = concept + proc p(s: Self) : Future[void] + SyncImpl = object + AsyncImpl = object + Container[T] = object + + proc p(x: SyncImpl) = discard + proc p(x: AsyncImpl): Future[void] = discard + + proc p(x: Container[SyncType]) = discard + proc p(x: Container[AsyncImpl]): Future[void] = discard + + assert SyncImpl is SyncType + assert SyncImpl isnot AsyncType + assert AsyncImpl isnot SyncType + assert AsyncImpl is AsyncType + assert Container[SyncImpl] is SyncType + assert Container[SyncImpl] isnot AsyncType + assert Container[AsyncImpl] isnot SyncType + assert Container[AsyncImpl] is AsyncType + # this code fails inside a block for some reason type Indexable[T] = concept proc `[]`(t: Self, i: int): T