towards support for composite type classes such as seq[Number] and SquareMatrix[T]
This commit is contained in:
parent
4eea2f17d3
commit
a27eb51535
8 changed files with 87 additions and 26 deletions
30
tests/compile/tcompositetypeclasses.nim
Normal file
30
tests/compile/tcompositetypeclasses.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
template accept(e) =
|
||||
static: assert(compiles(e))
|
||||
|
||||
template reject(e) =
|
||||
static: assert(not compiles(e))
|
||||
|
||||
type
|
||||
TFoo[T, U] = tuple
|
||||
x: T
|
||||
y: U
|
||||
|
||||
TBar[K] = TFoo[K, K]
|
||||
|
||||
TUserClass = int|string
|
||||
|
||||
# TBaz = TBar[TUserClass]
|
||||
|
||||
var
|
||||
vfoo: TFoo[int, string]
|
||||
vbar: TFoo[string, string]
|
||||
|
||||
proc foo(x: TFoo) = echo "foo"
|
||||
proc bar(x: TBar) = echo "bar"
|
||||
# proc baz(x: TBaz) = echo "baz"
|
||||
|
||||
accept(foo(vfoo))
|
||||
accept(bar(vbar))
|
||||
# baz vbar
|
||||
reject(bar(vfoo))
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue