File tree 1 file changed +65
-0
lines changed
1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ discard """
2
+ action: compile
3
+ """
4
+
5
+ {.experimental : " strictFuncs" .}
6
+
7
+ func sortedFake1 [T](a: openArray [T]): seq [T] =
8
+ for i in 0 .. a.high: result .add a[i]
9
+ func sortedFake2 [T](a: openArray [T]): seq [T] =
10
+ result = newSeq [T](a.len)
11
+ for i in 0 .. a.high: result [i] = a[i]
12
+ type Foo1 = object
13
+ type Foo2 = ref object
14
+ block :
15
+ let a1 = sortedFake1 ([Foo1 ()]) # ok
16
+ let a2 = sortedFake1 ([Foo2 ()]) # ok
17
+ block :
18
+ let a1 = sortedFake2 ([Foo1 ()]) # ok
19
+ let a2 = sortedFake2 ([Foo2 ()]) # error: Error: 'sortedFake2' can have side effects
20
+
21
+
22
+ import std/ sequtils
23
+ type Foob = ref object
24
+ x: int
25
+ let a1 = zip (@ [1 ,2 ], @ [1 ,2 ]) # ok
26
+ let a2 = zip (@ [Foob (x: 1 )], @ [Foob (x: 2 )]) # error in 1.6.0 RC2, but not 1.4.x
27
+
28
+
29
+ # bug #20863
30
+ type
31
+ Fooc = ref object
32
+
33
+ func twice (foo: Fooc ) =
34
+ var a = newSeq [Fooc ](2 )
35
+ a[0 ] = foo # No error.
36
+ a[1 ] = foo # Error: 'twice' can have side effects.
37
+
38
+ let foo = Fooc ()
39
+ twice (foo)
40
+
41
+ # bug #17387
42
+ import json
43
+
44
+ func parseColumn (columnNode: JsonNode ) =
45
+ let columnName = columnNode[" name" ].str
46
+
47
+ parseColumn (%* {" a" : " b" })
48
+
49
+ type
50
+ MyTable = object
51
+ data: seq [int ]
52
+
53
+ JsonNode3 = ref object
54
+ fields: MyTable
55
+
56
+ proc `[]` (t: var MyTable , key: string ): var int =
57
+ result = t.data[0 ]
58
+
59
+ proc `[]` (x: JsonNode3 , key: string ): int =
60
+ result = x.fields[key]
61
+
62
+ func parseColumn (columnNode: JsonNode3 ) =
63
+ var columnName = columnNode[" test" ]
64
+
65
+ parseColumn (JsonNode3 ())
You can’t perform that action at this time.
0 commit comments