Skip to content

Commit 2b699bc

Browse files
authored
new-style concepts - small bugfix (#24778)
1 parent fb93295 commit 2b699bc

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

compiler/concepts.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ proc matchType(c: PContext; fo, ao: PType; m: var MatchCon): bool =
280280
if f.isConcept:
281281
if a.acceptsAllTypes:
282282
return false
283-
if a.isConcept:
283+
if a.skipTypes(ignorableForArgType).isConcept:
284284
# if f is a subset of a then any match to a will also match f. Not the other way around
285285
return conceptsMatch(c, a.reduceToBase, f.reduceToBase, m) >= mkSubset
286286
else:
@@ -319,7 +319,11 @@ proc matchType(c: PContext; fo, ao: PType; m: var MatchCon): bool =
319319
if a.kind in ignorableForArgType:
320320
result = matchType(c, f, a.skipTypes(ignorableForArgType), m)
321321
else:
322-
result = sameType(f, a)
322+
if a.kind == tyGenericInst:
323+
# tyOr does this to generic typeclasses
324+
result = a.base.sym == f.sym
325+
else:
326+
result = sameType(f, a)
323327
of tyEmpty, tyString, tyCstring, tyPointer, tyNil, tyUntyped, tyTyped, tyVoid:
324328
result = a.skipTypes(ignorableForArgType).kind == f.kind
325329
of tyBool, tyChar, tyInt..tyUInt64:

tests/concepts/tconceptsv2.nim

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ block:
392392
393393
proc p[X, Y](z: var A[int, float]) = discard
394394
proc g[X, Y](z: var A[X, Y], y: int) = discard
395-
proc h[X, Y](z: var A[X, Y]): A[X, Y] = discard
395+
proc h[X, Y](z: A[X, Y]): A[X, Y] = discard
396396
397397
proc spring(x: C4) = discard
398398
var d = A[int, float]()
@@ -428,6 +428,37 @@ block:
428428
429429
assert spring(Impl()) == 2
430430
431+
block:
432+
type
433+
C1[T] = concept
434+
proc p(s: var Self; x: T)
435+
FreakString = concept
436+
proc p(w: var C1; s: Self)
437+
proc a(x: Self)
438+
DynArray[CT, T] = object
439+
440+
proc p[CT; T; W; ](w: C1[T]; o: DynArray[CT, T]): int = discard
441+
proc spring(s: auto) = discard
442+
proc spring(s: FreakString) = discard
443+
444+
spring("hi")
445+
446+
block:
447+
type
448+
RawWriter = concept
449+
proc write(s: Self; data: pointer; length: int)
450+
ArrayBuffer[N: static int] = object
451+
SeqBuffer = object
452+
CompatBuffer = ArrayBuffer | SeqBuffer
453+
454+
proc write[T:CompatBuffer](a: var T; data: pointer; length: int) =
455+
discard
456+
457+
proc spring(r:RawWriter, i: byte)=discard
458+
459+
var s = ArrayBuffer[1500]()
460+
spring(s, 8.uint8)
461+
431462
# this code fails inside a block for some reason
432463
type Indexable[T] = concept
433464
proc `[]`(t: Self, i: int): T

0 commit comments

Comments
 (0)