diff options
author | Araq <rumpf_a@web.de> | 2018-08-31 17:27:57 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-08-31 17:27:57 +0200 |
commit | e09eeb02bf92b4bdcfb7a821014bedf71c753a95 (patch) | |
tree | 5f585ed571c63e4fdf5f0bd54d1a7855ed188c3f /tests/template | |
parent | 2c8361bd39f98c869df7b23ee682c25a9929f64f (diff) | |
download | Nim-e09eeb02bf92b4bdcfb7a821014bedf71c753a95.tar.gz |
fixes #8052
Diffstat (limited to 'tests/template')
-rw-r--r-- | tests/template/tnested_template.nim | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/template/tnested_template.nim b/tests/template/tnested_template.nim new file mode 100644 index 000000000..37166009d --- /dev/null +++ b/tests/template/tnested_template.nim @@ -0,0 +1,23 @@ +# bug #8052 + +type + UintImpl*[N: static[int], T: SomeUnsignedInt] = object + raw_data*: array[N, T] + +template genLoHi(TypeImpl: untyped): untyped = + template loImpl[N: static[int], T: SomeUnsignedInt](dst: TypeImpl[N div 2, T], src: TypeImpl[N, T]) = + let halfSize = N div 2 + for i in 0 ..< halfSize: + dst.raw_data[i] = src.raw_data[i] + + proc lo*[N: static[int], T: SomeUnsignedInt](x: TypeImpl[N,T]): TypeImpl[N div 2, T] {.inline.}= + loImpl(result, x) + +genLoHi(UintImpl) + +var a: UintImpl[4, uint32] + +a.raw_data = [1'u32, 2'u32, 3'u32, 4'u32] +assert a.lo.raw_data.len == 2 +assert a.lo.raw_data[0] == 1 +assert a.lo.raw_data[1] == 2 |