summary refs log tree commit diff stats
path: root/tests/template/tgensymregression.nim
blob: 0fadbde417258b6b49691c3fa4fe573affc2e2a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
discard """
  output: '''[0.0, 0.0, 0.0]

[0.0, 0.0, 0.0, 0.0]

5050
123'''
"""

template mathPerComponent(op: untyped): untyped =
  proc op*[N,T](v,u: array[N,T]): array[N,T] {.inline.} =
    for i in 0 ..< len(result):
      result[i] = `*`(v[i], u[i])

mathPerComponent(`***`)
# bug #5285
when true:
  if isMainModule:
    var v1: array[3, float64]
    var v2: array[3, float64]
    echo repr(v1 *** v2)


proc foo(): void =
  var v1: array[4, float64]
  var v2: array[4, float64]
  echo repr(v1 *** v2)

foo()

# bug #5383
import sequtils

proc zipWithIndex[A](ts: seq[A]): seq[(int, A)] =
  toSeq(pairs(ts))

proc main =
  discard zipWithIndex(@["foo", "bar"])
  discard zipWithIndex(@[1, 2])
  discard zipWithIndex(@[true, false])

main()

# bug #5405

proc main2() =
  let s = toSeq(1..100).foldL(a + b)
  echo s

main2()

# bug #5467
import macros

converter int2string(x: int): string = $x

template wrap(body: typed): untyped =
  body

macro makeProc(): typed =
  # Make a template tree
  result = (quote do:
    proc someProc* =
      wrap do:
        let x = 123
        # Implicit conversion here
        let s: string = x
        echo s
  )

makeProc()

someProc()