summary refs log tree commit diff stats
path: root/tests/trmacros
diff options
context:
space:
mode:
authorJacek Sieka <arnetheduck@gmail.com>2016-08-25 22:59:51 +0800
committerJacek Sieka <arnetheduck@gmail.com>2016-08-25 22:59:51 +0800
commitdb2f96daba9c04db2f24cb783c79fb37799cd9ea (patch)
tree567beb43c7e4549abfcae1ea66e5232d7525e001 /tests/trmacros
parent3116744c86f37ac4e4e5fec3d6d1635304ed717f (diff)
parent84a09d2f5b0866491e55fef0fef541e8cc548852 (diff)
downloadNim-db2f96daba9c04db2f24cb783c79fb37799cd9ea.tar.gz
Merge remote-tracking branch 'origin/devel' into initallocator-fix
Diffstat (limited to 'tests/trmacros')
-rw-r--r--tests/trmacros/tpatterns.nim8
-rw-r--r--tests/trmacros/tstatic_t_bug.nim24
2 files changed, 31 insertions, 1 deletions
diff --git a/tests/trmacros/tpatterns.nim b/tests/trmacros/tpatterns.nim
index 6bc8772e3..907973637 100644
--- a/tests/trmacros/tpatterns.nim
+++ b/tests/trmacros/tpatterns.nim
@@ -1,6 +1,7 @@
 discard """
   output: '''48
-hel'''
+hel
+lo'''
 """
 
 template optZero{x+x}(x: int): int = x*3
@@ -15,3 +16,8 @@ s[0] = "hello"
 s[0] = substr(s[0], 0, 2)
 
 echo s[0]
+
+# Test varargs matching
+proc someVarargProc(k: varargs[string]) = doAssert(false) # this should not get called
+template someVarargProcSingleArg{someVarargProc([a])}(a: string) = echo a
+someVarargProc("lo")
diff --git a/tests/trmacros/tstatic_t_bug.nim b/tests/trmacros/tstatic_t_bug.nim
new file mode 100644
index 000000000..cdfa53514
--- /dev/null
+++ b/tests/trmacros/tstatic_t_bug.nim
@@ -0,0 +1,24 @@
+discard """
+  output: "optimized"
+"""
+# bug #4227
+type Vector64[N: static[int]] = array[N, int]
+
+proc `*`*[N: static[int]](a: Vector64[N]; b: float64): Vector64[N] =
+  result = a
+
+proc `+=`*[N: static[int]](a: var Vector64[N]; b: Vector64[N]) =
+  echo "regular"
+
+proc linearCombinationMut[N: static[int]](a: float64, v: var Vector64[N], w: Vector64[N])  {. inline .} =
+  echo "optimized"
+
+template rewriteLinearCombinationMut*{v += `*`(w, a)}(a: float64, v: var Vector64, w: Vector64): auto =
+  linearCombinationMut(a, v, w)
+
+proc main() =
+  const scaleVal = 9.0
+  var a, b: Vector64[7]
+  a += b * scaleval
+
+main()