forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for v1 closed generics/static issues (nim-lang#8572)
* Add tests to confirm nim-lang#7231 is fixed. * Add test for closed nim-lang#6137 * Add test for nim-lang#7141
- Loading branch information
1 parent
61afed1
commit cc590fa
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters