summary refs log blame commit diff stats
path: root/tests/ccgbugs/t6279.nim
blob: 37345d807ba3d28df7ed948c2f828a39c76f51bc (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                           
discard """
cmd: "nim c -r -d:fulldebug -d:smokeCycles --gc:refc $file"
output: '''@[a]'''
"""

# bug #6279
var foo = newSeq[tuple[a: seq[string], b: seq[string]]]()
foo.add((@["a"], @["b"]))
echo foo[0].a # Crashes on this line
21e22624a ^















d0a9fac36 ^



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
           










                                                     

                



                     
                

                










                            
             
             
                                  
 

                 
                                                                                



            











                                                    
        















                                             



                                            
discard """
  output: '''
(k: kindA, a: (x: "abc", z: @[1, 1, 3]), method: ())
(k: kindA, a: (x: "abc", z: @[1, 2, 3]), method: ())
(k: kindA, a: (x: "abc", z: @[1, 3, 3]), method: ())
(k: kindA, a: (x: "abc", z: @[1, 4, 3]), method: ())
(k: kindA, a: (x: "abc", z: @[1, 5, 3]), method: ())
(k: kindA, a: (x: "abc", z: @[1, 6, 3]), method: ())
(k: kindA, a: (x: "abc", z: @[1, 7, 3]), method: ())
(k: kindA, a: (x: "abc", z: @[1, 8, 3]), method: ())
(k: kindA, a: (x: "abc", z: @[1, 9, 3]), method: ())
(k: kindA, a: (x: "abc", z: @[1, 10, 3]), method: ())
(y: 0, x: 123)
(y: 678, x: 123)
(z: 89, y: 0, x: 128)
(y: 678, x: 123)
(y: 678, x: 123)
(y: 0, x: 123)
(y: 678, x: 123)
(y: 123, x: 678)
'''
"""

type
  TArg = object
    x: string
    z: seq[int]
  TKind = enum kindXY, kindA
  TEmpty = object
  TDummy = ref object
    case k: TKind
    of kindXY: x, y: int
    of kindA:
      a: TArg
      `method`: TEmpty # bug #1791

proc main() =
  for i in 1..10:
    let d = TDummy(k: kindA, a: TArg(x: "abc", z: @[1,i,3]), `method`: TEmpty())
    echo d[]

main()

# bug #6294
type
  A = object of RootObj
    x*: int
  B = object of A
    y*: int
  BS = object of B
  C = object of BS
    z*: int
# inherited fields are ignored, so no fields are set
when true:
  var
    o: B
  o = B(x: 123)
  echo o
  o = B(y: 678, x: 123)
  echo o

# inherited fields are ignored
echo C(x: 128, z: 89)          # (y: 0, x: 0)
echo B(y: 678, x: 123)  # (y: 678, x: 0)
echo B(x: 123, y: 678)  # (y: 678, x: 0)

when true:
  # correct, both with `var` and `let`;
  var b=B(x: 123)
  echo b                  # (y: 0, x: 123)
  b=B(y: 678, x: 123)
  echo b                  # (y: 678, x: 123)
  b=B(y: b.x, x: b.y)
  echo b                  # (y: 123, x: 678)

GC_fullCollect()