From d141c05f4a0f87e116ea22301cbe0f8ffd151c97 Mon Sep 17 00:00:00 2001 From: metagn Date: Sat, 5 Oct 2024 21:10:14 +0300 Subject: [PATCH] make new concepts match themselves fixes #22839 --- compiler/sigmatch.nim | 7 +++++-- tests/concepts/tintypesection.nim | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/concepts/tintypesection.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 6ea2c7bb5781..bbebbb096cf6 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1899,8 +1899,11 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, else: result = isNone of tyConcept: - result = if concepts.conceptMatch(c.c, f, a, c.bindings, nil): isGeneric - else: isNone + if a.kind == tyConcept and sameType(f, a): + result = isGeneric + else: + result = if concepts.conceptMatch(c.c, f, a, c.bindings, nil): isGeneric + else: isNone of tyCompositeTypeClass: considerPreviousT: let roota = a.skipGenericAlias diff --git a/tests/concepts/tintypesection.nim b/tests/concepts/tintypesection.nim new file mode 100644 index 000000000000..92af7ebb54b4 --- /dev/null +++ b/tests/concepts/tintypesection.nim @@ -0,0 +1,22 @@ +# issues with concepts in type section types + +block: # issue #22839 + type + Comparable = concept + proc `<`(a, b: Self): bool + + # Works with this. + # Comparable = concept a + # `<`(a, a) is bool + + # Doesn't work with the new style concept. + Node[T: Comparable] = object + data: T + next: ref Node[T] + + var x: Node[int] + type NotComparable = object + doAssert not (compiles do: + var y: Node[NotComparable]) + proc `<`(a, b: NotComparable): bool = false + var z: Node[NotComparable]