summary refs log tree commit diff stats
path: root/tests/macros/tbugs.nim
blob: 1bfce6bc49e2449f5c9e8ed5310e333e0be1425b (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
discard """
msg: '''a
s
d
f
TTaa
TTaa
TTaa
TTaa
true
true
nil
42
false
true'''

output: '''test
2'''
"""

type
  Foo = object
    s: char

iterator test2(f: string): Foo =
  for i in f:
    yield Foo(s: i)

macro test(): stmt =
  for i in test2("asdf"):
    echo i.s

test()


# bug 1297

import macros

type TType = tuple[s: string]

macro echotest(): stmt =
  var t: TType
  t.s = ""
  t.s.add("test")
  result = newCall(newIdentNode("echo"), newStrLitNode(t.s))

echotest()

# bug #1103

type
    Td = tuple
        a:string
        b:int

proc get_data(d: Td) : string {.compileTime.} =
    result = d.a # Works if a literal string is used here.
    # Bugs if line A or B is active. Works with C
    result &= "aa"          # A
    #result.add("aa")       # B
    #result = result & "aa" # C

macro m(s:static[Td]) : stmt =
    echo get_data(s)
    echo get_data(s)
    result = newEmptyNode()

const s=("TT", 3)
m(s)
m(s)

# bug #933

proc nilcheck(): NimNode {.compileTime.} =
  echo(result == nil) # true
  echo(result.isNil) # true
  echo(repr(result)) # nil

macro testnilcheck(): stmt =
  result = newNimNode(nnkStmtList)
  discard nilcheck()

testnilcheck()

# bug #1323

proc calc(): array[1, int] =
  result[0].inc()
  result[0].inc()

const c = calc()
echo c[0]


# bug #3046

macro sampleMacroInt(i: int): stmt =
  echo i.intVal

macro sampleMacroBool(b: bool): stmt =
  echo b.boolVal

sampleMacroInt(42)
sampleMacroBool(false)
sampleMacroBool(system.true)