66class X { }
77
88struct 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+
919#if EMPTY
1020#elseif TRIVIAL
1121 var x : Int = 0
@@ -23,6 +33,10 @@ struct S {
2333 var data : NC {
2434 _read { yield NC ( ) }
2535 }
36+
37+ subscript( index: Int ) -> NC {
38+ _read { yield NC ( ) }
39+ }
2640}
2741
2842struct SNC : ~ Copyable {
@@ -31,6 +45,10 @@ struct SNC: ~Copyable {
3145 var data : NC {
3246 _read { yield _data }
3347 }
48+
49+ subscript( index: Int ) -> NC {
50+ _read { yield _data }
51+ }
3452}
3553
3654class C {
@@ -39,35 +57,84 @@ class C {
3957 var data : NC {
4058 _read { yield _data }
4159 }
60+
61+ subscript( index: Int ) -> NC {
62+ _read { yield _data }
63+ }
4264}
4365
4466protocol P {
4567 @_borrowed
4668 var data : NC { get }
69+
70+ @_borrowed
71+ subscript( index: Int ) -> NC { get }
4772}
4873
4974func borrow( _ nc: borrowing NC ) { }
5075func take( _ nc: consuming NC ) { }
5176
77+ func assume( _ b: Bool ) { precondition ( b, " uh oh " ) }
78+
5279func test( c: C ) {
5380 borrow ( c. data)
5481 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?
5590}
5691func test( s: S ) {
5792 borrow ( s. data)
5893 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?
59102}
60103func test( snc: borrowing SNC ) {
61104 borrow ( snc. data)
62105 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?
63114}
64115
65116func test< T: P > ( t: T ) {
66117 borrow ( t. data)
67118 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?
68127}
69128func test( p: P ) {
70129 borrow ( p. data)
71130 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?
72139}
73140
0 commit comments