summary refs log tree commit diff stats
path: root/tests/trmacros
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-05-27 19:17:51 +0200
committerAndreas Rumpf <rumpf_a@web.de>2016-05-27 19:18:08 +0200
commit6d76df84546dd90d33a413c0bbd8df75f797767a (patch)
tree1deca5384e48fc7c7c642761843b83a1ee9cf228 /tests/trmacros
parent6ff66bfd519f076b5453b1bdcf94086b4ee658f4 (diff)
downloadNim-6d76df84546dd90d33a413c0bbd8df75f797767a.tar.gz
fixes #4227
Diffstat (limited to 'tests/trmacros')
-rw-r--r--tests/trmacros/tstatic_t_bug.nim24
1 files changed, 24 insertions, 0 deletions
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()