6
6
class X { }
7
7
8
8
struct NC: ~ Copyable {
9
+ var field : Int = 0
10
+ var consumingGetter : Int {
11
+ consuming get { return 0 }
12
+ }
13
+ var readCoroutine : Int {
14
+ _read { yield field }
15
+ }
16
+ consuming func consumingFunc( ) -> Int { return 0 }
17
+ borrowing func borrowingFunc( ) -> Int { return 0 }
18
+
9
19
#if EMPTY
10
20
#elseif TRIVIAL
11
21
var x : Int = 0
@@ -23,6 +33,10 @@ struct S {
23
33
var data : NC {
24
34
_read { yield NC ( ) }
25
35
}
36
+
37
+ subscript( index: Int ) -> NC {
38
+ _read { yield NC ( ) }
39
+ }
26
40
}
27
41
28
42
struct SNC : ~ Copyable {
@@ -31,6 +45,10 @@ struct SNC: ~Copyable {
31
45
var data : NC {
32
46
_read { yield _data }
33
47
}
48
+
49
+ subscript( index: Int ) -> NC {
50
+ _read { yield _data }
51
+ }
34
52
}
35
53
36
54
class C {
@@ -39,35 +57,84 @@ class C {
39
57
var data : NC {
40
58
_read { yield _data }
41
59
}
60
+
61
+ subscript( index: Int ) -> NC {
62
+ _read { yield _data }
63
+ }
42
64
}
43
65
44
66
protocol P {
45
67
@_borrowed
46
68
var data : NC { get }
69
+
70
+ @_borrowed
71
+ subscript( index: Int ) -> NC { get }
47
72
}
48
73
49
74
func borrow( _ nc: borrowing NC ) { }
50
75
func take( _ nc: consuming NC ) { }
51
76
77
+ func assume( _ b: Bool ) { precondition ( b, " uh oh " ) }
78
+
52
79
func test( c: C ) {
53
80
borrow ( c. data)
54
81
take ( c. data) // expected-error{{'c.data' is borrowed and cannot be consumed}} expected-note{{consumed here}}
82
+
83
+ borrow ( c [ 0 ] )
84
+ assume ( c [ 0 ] . field == 0 )
85
+ assume ( c [ 0 ] . borrowingFunc ( ) == 0 )
86
+ assume ( c [ 0 ] . readCoroutine == 0 )
87
+ // take(c[0]) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
88
+ assume ( c [ 0 ] . consumingGetter == 0 ) // expected-error {{'c.subscript' is borrowed and cannot be consumed}} expected-note {{consumed here}}
89
+ // assume(c[0].consumingFunc() == 0) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
55
90
}
56
91
func test( s: S ) {
57
92
borrow ( s. data)
58
93
take ( s. data) // expected-error{{'s.data' is borrowed and cannot be consumed}} expected-note{{consumed here}}
94
+
95
+ borrow ( s [ 0 ] )
96
+ assume ( s [ 0 ] . field == 0 )
97
+ assume ( s [ 0 ] . borrowingFunc ( ) == 0 )
98
+ assume ( s [ 0 ] . readCoroutine == 0 )
99
+ // take(s[0]) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
100
+ assume ( s [ 0 ] . consumingGetter == 0 ) // expected-error {{'s.subscript' is borrowed and cannot be consumed}} expected-note {{consumed here}}
101
+ // assume(s[0].consumingFunc() == 0) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
59
102
}
60
103
func test( snc: borrowing SNC ) {
61
104
borrow ( snc. data)
62
105
take ( snc. data) // expected-error{{'snc.data' is borrowed and cannot be consumed}} expected-note{{consumed here}}
106
+
107
+ borrow ( snc [ 0 ] )
108
+ assume ( snc [ 0 ] . field == 0 )
109
+ assume ( snc [ 0 ] . borrowingFunc ( ) == 0 )
110
+ assume ( snc [ 0 ] . readCoroutine == 0 )
111
+ // take(snc[0]) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
112
+ assume ( snc [ 0 ] . consumingGetter == 0 ) // expected-error {{'snc.subscript' is borrowed and cannot be consumed}} expected-note {{consumed here}}
113
+ // assume(snc[0].consumingFunc() == 0) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
63
114
}
64
115
65
116
func test< T: P > ( t: T ) {
66
117
borrow ( t. data)
67
118
take ( t. data) // expected-error{{'t.data' is borrowed and cannot be consumed}} expected-note{{consumed here}}
119
+
120
+ borrow ( t [ 0 ] )
121
+ assume ( t [ 0 ] . field == 0 )
122
+ assume ( t [ 0 ] . borrowingFunc ( ) == 0 )
123
+ assume ( t [ 0 ] . readCoroutine == 0 )
124
+ // take(t[0]) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
125
+ assume ( t [ 0 ] . consumingGetter == 0 ) // expected-error {{'t.subscript' is borrowed and cannot be consumed}} expected-note {{consumed here}}
126
+ // assume(t[0].consumingFunc() == 0) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
68
127
}
69
128
func test( p: P ) {
70
129
borrow ( p. data)
71
130
take ( p. data) // expected-error{{'p.data' is borrowed and cannot be consumed}} expected-note{{consumed here}}
131
+
132
+ borrow ( p [ 0 ] )
133
+ assume ( p [ 0 ] . field == 0 )
134
+ assume ( p [ 0 ] . borrowingFunc ( ) == 0 )
135
+ assume ( p [ 0 ] . readCoroutine == 0 )
136
+ // take(p[0]) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
137
+ assume ( p [ 0 ] . consumingGetter == 0 ) // expected-error {{'p.subscript' is borrowed and cannot be consumed}} expected-note {{consumed here}}
138
+ // assume(p[0].consumingFunc() == 0) // FIXME: the move-checker's diagnostics produced for this code are non-deterministic?
72
139
}
73
140
0 commit comments