tstatic_t_bug.nim 615 B

12345678910111213141516171819202122232425
  1. discard """
  2. output: "optimized"
  3. """
  4. # bug #4227
  5. type Vector64[N: static[int]] = array[N, int]
  6. proc `*`*[N: static[int]](a: Vector64[N]; b: float64): Vector64[N] =
  7. result = a
  8. proc `+=`*[N: static[int]](a: var Vector64[N]; b: Vector64[N]) =
  9. echo "regular"
  10. proc linearCombinationMut[N: static[int]](a: float64, v: var Vector64[N], w: Vector64[N]) {. inline .} =
  11. echo "optimized"
  12. template rewriteLinearCombinationMut*{v += `*`(w, a)}(a: float64, v: var Vector64, w: Vector64): auto =
  13. linearCombinationMut(a, v, w)
  14. proc main() =
  15. const scaleVal = 9.0
  16. var a, b: Vector64[7]
  17. a += b * scaleval
  18. main()