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
This commit is contained in:
Mamy Ratsimbazafy
2018-08-08 17:49:33 +02:00
committed by Andreas Rumpf
parent 506418ef53
commit bccaa36aba
3 changed files with 51 additions and 0 deletions

29
tests/generics/t6137.nim Normal file
View File

@@ -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)

10
tests/generics/t7141.nim Normal file
View File

@@ -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

View File

@@ -99,3 +99,15 @@ echo sizeof(a)
echo sizeof(b)
echo sizeof(c)
# This is the same example but using a proc instead of a macro
# Instead of type mismatch for macro, proc just failed with internal error: getTypeDescAux(tyNone)
# https://github.com/nim-lang/Nim/issues/7231
proc getBase2*(bits: static[int]): typedesc =
if bits == 128:
result = newTree(nnkBracketExpr, ident("MpUintBase"), ident("uint64"))
else:
result = newTree(nnkBracketExpr, ident("MpUintBase"), ident("uint32"))
type
MpUint2*[bits: static[int]] = getbase2(bits)