diff options
author | Mamy Ratsimbazafy <mratsim@users.noreply.github.com> | 2018-08-08 17:49:33 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-08 17:49:33 +0200 |
commit | bccaa36aba64d2424ceedc9723d5ec01534dde94 (patch) | |
tree | aea315c548d0edf465494339c07237d20259c947 /tests/generics | |
parent | 506418ef539a9142307235c0cd0183f0d7aec749 (diff) | |
download | Nim-bccaa36aba64d2424ceedc9723d5ec01534dde94.tar.gz |
Tests for v1 closed generics/static issues (#8572)
* Add tests to confirm https://github.com/nim-lang/Nim/issues/7231 is fixed. * Add test for closed https://github.com/nim-lang/Nim/issues/6137 * Add test for https://github.com/nim-lang/Nim/issues/7141
Diffstat (limited to 'tests/generics')
-rw-r--r-- | tests/generics/t6137.nim | 29 | ||||
-rw-r--r-- | tests/generics/t7141.nim | 10 |
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/generics/t6137.nim b/tests/generics/t6137.nim new file mode 100644 index 000000000..639675f35 --- /dev/null +++ b/tests/generics/t6137.nim @@ -0,0 +1,29 @@ +discard """ + action: "reject" + line: 29 + errormsg: "\'vectFunc\' doesn't have a concrete type, due to unspecified generic parameters." +""" + +type + # simple vector of declared fixed length + vector[N : static[int]] = array[0..N-1, float] + +proc `*`[T](x: float, a: vector[T]): vector[T] = + # multiplication by scalar + for ii in 0..high(a): + result[ii] = a[ii]*x + +let + # define a vector of length 3 + x: vector[3] = [1.0, 3.0, 5.0] + +proc vectFunc[T](x: vector[T]): vector[T] {.procvar.} = + # Define a vector function + result = 2.0*x + +proc passVectFunction[T](g: proc(x: vector[T]): vector[T], x: vector[T]): vector[T] = + # pass a vector function as input in another procedure + result = g(x) + +let + xNew = passVectFunction(vectFunc,x) diff --git a/tests/generics/t7141.nim b/tests/generics/t7141.nim new file mode 100644 index 000000000..8a128d828 --- /dev/null +++ b/tests/generics/t7141.nim @@ -0,0 +1,10 @@ +discard """ + action: "reject" + line: 7 + errormsg: "cannot instantiate: \'T\'" +""" + +proc foo[T](x: T) = + discard + +var fun = if true: foo else: foo |