* hangle static generic params when used in the importcpp pragma

* importcpp works for generic types with fields; fixes #6415

* revert a too agressive safety check that ended up breaking the tests
This commit is contained in:
zah 2018-03-08 16:10:45 +02:00 • committed by Andreas Rumpf
commit cbd059aa85
4 changed files with 71 additions and 6 deletions

View file

@ -0,0 +1,53 @@
discard """
targets: "cpp"
output: "[0, 0, 10, 0]\n5\n1.2\n15\ntest"
"""
{.emit: """
template <int N, class T>
struct GenericIntType {
T data[N];
};
template <class T>
struct GenericTType {
T field;
};
struct SimpleStruct {
int field;
};
""" .}
type
GenericIntType {.importcpp: "GenericIntType<'0, '1>".} [N: static[int]; T] = object
data: array[N, T]
GenericTType {.importcpp: "GenericTType<'0>".} [T] = object
field: T
GenInt4 = GenericIntType[4, int]
SimpleStruct {.importcpp: "SimpleStruct"} = object
field: int
var
a = GenInt4()
b = SimpleStruct()
c = GenericTType[float]()
d = SimpleStruct(field: 15)
e = GenericTType[string](field: "test")
a.data[2] = 10
b.field = 5
c.field = 1.2
echo a.data
echo b.field
echo c.field
echo d.field
echo e.field