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
|
discard """
cmd: "nim c --gc:arc $file"
output: '''5
(w: 5)
(w: -5)
'''
"""
# move bug
type
TMyObj = object
p: pointer
len: int
var destroyCounter = 0
proc `=destroy`(o: var TMyObj) =
if o.p != nil:
dealloc o.p
o.p = nil
inc destroyCounter
proc `=`(dst: var TMyObj, src: TMyObj) =
`=destroy`(dst)
dst.p = alloc(src.len)
dst.len = src.len
proc `=sink`(dst: var TMyObj, src: TMyObj) =
`=destroy`(dst)
dst.p = src.p
dst.len = src.len
type
TObjKind = enum Z, A, B
TCaseObj = object
case kind: TObjKind
of Z: discard
of A:
x1: int # this int plays important role
x2: TMyObj
of B:
y: TMyObj
proc use(a: TCaseObj) = discard
proc moveBug(i: var int) =
var a: array[2, TCaseObj]
a[i] = TCaseObj(kind: A, x1: 5000, x2: TMyObj(len: 5, p: alloc(5))) # 1
a[i+1] = a[i] # 2
inc i
use(a[i-1])
var x = 0
moveBug(x)
proc moveBug2(): (TCaseObj, TCaseObj) =
var a: array[2, TCaseObj]
a[0] = TCaseObj(kind: A, x1: 5000, x2: TMyObj(len: 5, p: alloc(5)))
a[1] = a[0] # can move 3
result[0] = TCaseObj(kind: A, x1: 5000, x2: TMyObj(len: 5, p: alloc(5))) # 4
result[1] = result[0] # 5
proc main =
discard moveBug2()
main()
echo destroyCounter
# bug #13314
type
O = object
v: int
R = ref object
w: int
proc `$`(r: R): string = $r[]
proc tbug13314 =
var t5 = R(w: 5)
var execute = proc () =
echo t5
execute()
t5.w = -5
execute()
tbug13314()
#-------------------------------------------------------------------------
# bug #13368
import strutils
proc procStat() =
for line in @["a b", "c d", "e f"]:
let cols = line.splitWhitespace(maxSplit=1)
let x = cols[0]
let (nm, rest) = (cols[0], cols[1])
procStat()
|