new-style concepts - small bugfix (#24778)

This commit is contained in:
Ryan McConnell
2025-03-15 10:05:14 -04:00
committed by GitHub
parent fb93295344
commit 2b699bca53
2 changed files with 38 additions and 3 deletions

View File

@@ -280,7 +280,7 @@ proc matchType(c: PContext; fo, ao: PType; m: var MatchCon): bool =
if f.isConcept:
if a.acceptsAllTypes:
return false
if a.isConcept:
if a.skipTypes(ignorableForArgType).isConcept:
# if f is a subset of a then any match to a will also match f. Not the other way around
return conceptsMatch(c, a.reduceToBase, f.reduceToBase, m) >= mkSubset
else:
@@ -319,7 +319,11 @@ proc matchType(c: PContext; fo, ao: PType; m: var MatchCon): bool =
if a.kind in ignorableForArgType:
result = matchType(c, f, a.skipTypes(ignorableForArgType), m)
else:
result = sameType(f, a)
if a.kind == tyGenericInst:
# tyOr does this to generic typeclasses
result = a.base.sym == f.sym
else:
result = sameType(f, a)
of tyEmpty, tyString, tyCstring, tyPointer, tyNil, tyUntyped, tyTyped, tyVoid:
result = a.skipTypes(ignorableForArgType).kind == f.kind
of tyBool, tyChar, tyInt..tyUInt64:

View File

@@ -392,7 +392,7 @@ block:
proc p[X, Y](z: var A[int, float]) = discard
proc g[X, Y](z: var A[X, Y], y: int) = discard
proc h[X, Y](z: var A[X, Y]): A[X, Y] = discard
proc h[X, Y](z: A[X, Y]): A[X, Y] = discard
proc spring(x: C4) = discard
var d = A[int, float]()
@@ -428,6 +428,37 @@ block:
assert spring(Impl()) == 2
block:
type
C1[T] = concept
proc p(s: var Self; x: T)
FreakString = concept
proc p(w: var C1; s: Self)
proc a(x: Self)
DynArray[CT, T] = object
proc p[CT; T; W; ](w: C1[T]; o: DynArray[CT, T]): int = discard
proc spring(s: auto) = discard
proc spring(s: FreakString) = discard
spring("hi")
block:
type
RawWriter = concept
proc write(s: Self; data: pointer; length: int)
ArrayBuffer[N: static int] = object
SeqBuffer = object
CompatBuffer = ArrayBuffer | SeqBuffer
proc write[T:CompatBuffer](a: var T; data: pointer; length: int) =
discard
proc spring(r:RawWriter, i: byte)=discard
var s = ArrayBuffer[1500]()
spring(s, 8.uint8)
# this code fails inside a block for some reason
type Indexable[T] = concept
proc `[]`(t: Self, i: int): T