blob: badc66c1b78003022cb94e78bc7603bff1979816 (
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
|
discard """
output: '''
foo
'''
"""
block: # #12672
var a = @[1]
let i = 1
inc a[i-1]
var b: seq[int]
doAssertRaises(IndexDefect): inc b[0]
doAssertRaises(IndexDefect): inc b[i-1]
var x: seq[seq[int]]
doAssertRaises(IndexDefect): # not TypeError
inc x[0][i-1]
block: # #14087
type Obj = object
str: string
var s = @[Obj(str: "abc"), Obj(str: "def")]
s[1].str.add("ghi")
s[s.len - 1].str.add("jkl")
s[^1].str.add("mno")
s[s.high].str.add("pqr")
let slen = s.len
s[slen - 1].str.add("stu")
let shigh = s.high
s[shigh].str.add("vwx")
proc foo(): int =
echo "foo"
shigh
s[foo()].str.add("yz")
doAssert s[1].str == "defghijklmnopqrstuvwxyz"
block: # #14117
type
A = object
case kind: bool
of true:
sons: seq[int]
else: discard
var a = A(kind: true)
doAssert a.sons.len == 0
a.sons.add(1)
doAssert a.sons.len == 1
import tables
block: # #13966
var t: Table[int8, array[int8, seq[tuple[]]]]
t[0] = default(array[int8, seq[tuple[]]])
t[0][0].add ()
block: # #11783
proc fun(): string =
discard
var ret: string
ret.add fun()
doAssert ret == ""
block: # #12256
var x: bool
doAssert x == false
reset x
doAssert x == false
doAssert x != true
|