Skip to content

Commit

Permalink
compsite typclass
Browse files Browse the repository at this point in the history
  • Loading branch information
Graveflo committed Nov 27, 2024
1 parent 869feb0 commit 71402c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/concepts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ proc matchType(c: PContext; f, a: PType; m: var MatchCon): bool =
ak = last(a)
result = matchType(c, last(f), ak, m)
of tyCompositeTypeClass:
result = matchType(c, last(f), a, m)
var ak = if a.kind == tyCompositeTypeClass: a.last else: a
result = matchType(c, last(f), ak, m)
of tyArray, tyTuple, tyVarargs, tyOpenArray, tyRange, tySequence, tyRef, tyPtr,
tyGenericInst:
# ^ XXX Rewrite this logic, it's more complex than it needs to be.
Expand Down
14 changes: 14 additions & 0 deletions tests/concepts/tconceptsv2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,17 @@ block:
proc p(a: Buffer)=discard
var buffer = ArrayBuffer[5]()
p(buffer)

block: # composite typeclass matching
type
A[T] = object
Buffer = concept
proc put(s: Self, i: A)
BufferImpl = object
WritableImpl = object

proc launch(a: var Buffer)=discard
proc put(x: BufferImpl, i: A)=discard

var a = BufferImpl()
launch(a)

0 comments on commit 71402c3

Please sign in to comment.