summary refs log tree commit diff stats
path: root/tests/ccgbugs/tsamename3.nim
blob: ded18e9f8fafd639beffa584a06787707ae32f85 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
block: # bug #15526
  block:
    type Foo = ref object
      x1: int
    let f1 = Foo(x1: 1)
  block:
    type Foo = ref object
      x2: int
    let f2 = Foo(x2: 2)

block: # ditto
  template fn() =
    block:
      type Foo = ref object
        x1: int
      let f1 = Foo(x1: 1)
      doAssert f1.x1 == 1
    block:
      type Foo = ref object
        x2: int
      let f2 = Foo(x2: 2)
      doAssert f2.x2 == 2
  static: fn()
  fn()

block: # bug #17162
  template fn =
    var ret: string
    block:
      type A = enum a0, a1, a2
      for ai in A:
        ret.add $ai
    block:
      type A = enum b0, b1, b2, b3
      for ai in A:
        ret.add $ai
    doAssert ret == "a0a1a2b0b1b2b3"

  static: fn() # ok
  fn() # was bug

block: # ditto
  proc fn =
    var ret: string
    block:
      type A = enum a0, a1, a2
      for ai in A:
        ret.add $ai
    block:
      type A = enum b0, b1, b2, b3
      for ai in A:
        ret.add $ai
    doAssert ret == "a0a1a2b0b1b2b3"

  static: fn() # ok
  fn() # was bug

block: # bug #5170
  block:
    type Foo = object
      x1: int
    let f1 = Foo(x1: 1)
  block:
    type Foo = object
      x2: int
    let f2 = Foo(x2: 2)

block: # ditto
  block:
    type Foo = object
      bar: bool
    var f1: Foo

  block:
    type Foo = object
      baz: int
    var f2: Foo
    doAssert f2.baz == 0

  block:
    template fn() =
      block:
        type Foo = object
          x1: int
        let f1 = Foo(x1: 1)
        doAssert f1.x1 == 1
      block:
        type Foo = object
          x2: int
        let f2 = Foo(x2: 2)
        doAssert f2.x2 == 2
    static: fn()
    fn()

when true: # ditto, refs https://github.com/nim-lang/Nim/issues/5170#issuecomment-582712132
  type Foo1 = object # at top level
    bar: bool
  var f1: Foo1

  block:
    type Foo1 = object
      baz: int
    var f2: Foo1
    doAssert f2.baz == 0

block: # make sure `hashType` doesn't recurse infinitely
  type
    PFoo = ref object
      a, b: PFoo
      c: int
  var a: PFoo

block: # issue #22571
  macro foo(x: typed) =
    result = x

  block: # or `proc main =`
    foo:
      type Foo = object
    doAssert $Foo() == "()"