make new concepts match themselves (#24244)

fixes #22839
This commit is contained in:
metagn
2024-10-06 09:09:52 +03:00
committed by GitHub
parent 4a63186cda
commit 9e30b39412
2 changed files with 27 additions and 2 deletions

View File

@@ -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

View File

@@ -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]