diff --git a/compiler/concepts.nim b/compiler/concepts.nim index af06f8cdca..b18956c3b0 100644 --- a/compiler/concepts.nim +++ b/compiler/concepts.nim @@ -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: diff --git a/tests/concepts/tconceptsv2.nim b/tests/concepts/tconceptsv2.nim index 5befd2fafa..afa66eda33 100644 --- a/tests/concepts/tconceptsv2.nim +++ b/tests/concepts/tconceptsv2.nim @@ -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