summary refs log tree commit diff stats
path: root/tests/procvar
diff options
context:
space:
mode:
Diffstat (limited to 'tests/procvar')
-rw-r--r--tests/procvar/tgenericprocvar.nim5
-rw-r--r--tests/procvar/tprocvar.nim18
-rw-r--r--tests/procvar/tprocvar2.nim32
-rw-r--r--tests/procvar/tprocvars.nim6
4 files changed, 61 insertions, 0 deletions
diff --git a/tests/procvar/tgenericprocvar.nim b/tests/procvar/tgenericprocvar.nim
new file mode 100644
index 000000000..e642e3577
--- /dev/null
+++ b/tests/procvar/tgenericprocvar.nim
@@ -0,0 +1,5 @@
+proc foo[T](thing: T) =
+    discard thing
+
+var a: proc (thing: int) {.nimcall.} = foo[int]
+
diff --git a/tests/procvar/tprocvar.nim b/tests/procvar/tprocvar.nim
new file mode 100644
index 000000000..56f76c613
--- /dev/null
+++ b/tests/procvar/tprocvar.nim
@@ -0,0 +1,18 @@
+discard """
+  errormsg: "type mismatch"
+  line: 17
+  file: "tprocvar.nim"
+"""
+
+type
+  TCallback = proc (a, b: int)
+
+proc huh(x, y: var int) =
+  x = 0
+  y = x+1
+
+proc so(c: TCallback) =
+  c(2, 4)
+  
+so(huh)
+
diff --git a/tests/procvar/tprocvar2.nim b/tests/procvar/tprocvar2.nim
new file mode 100644
index 000000000..237e2ef7a
--- /dev/null
+++ b/tests/procvar/tprocvar2.nim
@@ -0,0 +1,32 @@
+discard """
+  file: "tprocvar.nim"
+  output: "papbpcpdpe7"
+"""
+# test variables of type proc

+
+proc pa() {.cdecl.} = write(stdout, "pa")
+proc pb() {.cdecl.} = write(stdout, "pb")
+proc pc() {.cdecl.} = write(stdout, "pc")
+proc pd() {.cdecl.} = write(stdout, "pd")
+proc pe() {.cdecl.} = write(stdout, "pe")
+
+const
+  algos = [pa, pb, pc, pd, pe]
+

+var

+  x: proc (a, b: int): int {.cdecl.}

+

+proc ha(c, d: int): int {.cdecl.} =

+  echo(c + d)

+  result = c + d

+
+for a in items(algos):
+  a()
+

+x = ha

+discard x(3, 4)

+

+#OUT papbpcpdpe7

+

+
+
diff --git a/tests/procvar/tprocvars.nim b/tests/procvar/tprocvars.nim
new file mode 100644
index 000000000..dc7592526
--- /dev/null
+++ b/tests/procvar/tprocvars.nim
@@ -0,0 +1,6 @@
+proc doSomething(v: Int, x: proc(v:Int):Int): Int = return x(v)
+proc doSomething(v: Int, x: proc(v:Int)) = x(v)
+
+
+echo doSomething(10, proc(v: Int): Int = return v div 2)
+