as I tried out, putting anything more complex is the static area of a generic
works in the beginning, but it will always make the compiler explode at some
point:
type IntAsType[N : static[int]] = object
proc foobar0[ValueA, ValueB](arg1: IntAsType[ValueA]; arg2:
IntAsType[ValueB]): void =
echo "foobar0"
echo ValueA
echo ValueB
echo "foobar0"
var
tmpA0 : IntAsType[7]
tmpB0 : IntAsType[8]
foobar0(tmpA0, tmpB0)
# this is the only case that works, everything else crashes during
compilation
type IntSeqAsType[Values : static[seq[int]]] = object
proc foobar1[SeqA, SeqB](arg1: IntSeqAsType[SeqA]; arg2:
IntSeqAsType[SeqB]): void =
echo "foobar1"
echo SeqA
echo SeqB
echo "foobar1"
var
tmpA1 : IntSeqAsType[@[1,2,3]]
tmpB1 : IntSeqAsType[@[4,5,6,7]]
foobar1(tmpA1, tmpB1)
# Error: internal error: genLiteral(nkBracket)
# No stack traceback available
# To create a stacktrace, rerun compilation with ./koch temp compile <file>
type IntOpenarrayAsType[Values : static[openarray[int]]] = object
proc foobar2[SeqA, SeqB](arg1: IntOpenarrayAsType[SeqA]; arg2:
IntOpenarrayAsType[SeqB]): void =
echo "foobar2"
echo SeqA
echo SeqB
echo "foobar2"
var
tmpA2 : IntOpenarrayAsType[[1,2,3]]
tmpB2 : IntOpenarrayAsType[[4,5,6,7]]
foobar2(tmpA2, tmpB2)
# Error: type mismatch: got (IntOpenarrayAsType[[1, 2, 3]],
IntOpenarrayAsType[[4, 5, 6, 7]])
# but expected one of:
# proc foobar2[SeqA, SeqB](arg1: IntOpenarrayAsType[SeqA];
# arg2: IntOpenarrayAsType[SeqB]): void
proc `$`(data : array[3,int]) : string =
result = "["
result &= $data[0]
for i in 1 .. high(data):
result &= ", "
result &= $data[1]
type IntArray3AsType[Values : static[array[3,int]]] = object
proc foobar3[SeqA, SeqB](arg1: IntArray3AsType[SeqA]; arg2:
IntArray3AsType[SeqB]): void =
echo "foobar3"
echo SeqA
echo SeqB
echo "foobar3"
var
tmpA3 : IntArray3AsType[[1,2,3]]
tmpB3 : IntArray3AsType[[4,5,6]]
foobar3(tmpA3, tmpB3)
# Error: internal error: genLiteral(nkBracket)
# No stack traceback available
# To create a stacktrace, rerun compilation with ./koch temp compile <file>