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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
// RUN: %target-swift-frontend -emit-sil -parse-stdlib -module-name Swift -verify %s
@_marker protocol Copyable {}
@_marker protocol Escapable {}
enum Optional<Wrapped: ~Copyable>: ~Copyable {
case none
case some(Wrapped)
}
extension Optional: Copyable where Wrapped: Copyable { }
func _diagnoseUnexpectedNilOptional(_filenameStart: Builtin.RawPointer,
_filenameLength: Builtin.Word,
_filenameIsASCII: Builtin.Int1,
_line: Builtin.Word,
_isImplicitUnwrap: Builtin.Int1) {
}
precedencegroup AssignmentPrecedence {}
struct NC: ~Copyable {
borrowing func b() {}
mutating func m() {}
consuming func c() {}
consuming func c2() -> NC { c2() } // expected-warning{{}}
consuming func c3() -> NCAO { c3() } // expected-warning{{}}
}
struct NCAO: ~Copyable {
var x: Any
borrowing func b() {}
mutating func m() {}
consuming func c() {}
consuming func c2() -> NC { c2() } // expected-warning{{}}
consuming func c3() -> NCAO { c3() } // expected-warning{{}}
}
func borrowingChains(nc: borrowing NC?, // expected-error{{'nc' is borrowed and cannot be consumed}}
ncao: borrowing NCAO?) { // expected-error{{'ncao' is borrowed and cannot be consumed}}
nc?.b()
nc?.c() // expected-note{{consumed here}}
ncao?.b()
ncao?.c() // expected-note{{consumed here}}
}
func borrowingChains2(nc: borrowing NC?,
ncao: borrowing NCAO?) {
nc?.b()
ncao?.b()
}
func mutatingChains(nc: inout NC?, // expected-error{{'nc' used after consume}}
ncao: inout NCAO?) { // expected-error{{'ncao' used after consume}}
nc?.b()
nc?.m()
nc?.c() // expected-note{{consumed here}}
nc?.b() // expected-note{{used here}}
nc?.m()
nc = .none
nc?.b()
nc?.m()
ncao?.b()
ncao?.m()
ncao?.c() // expected-note{{consumed here}}
ncao?.b() // expected-note{{used here}}
ncao?.m()
ncao = .none
ncao?.b()
ncao?.m()
}
func mutatingChains2(nc: inout NC?, // expected-error{{'nc' used after consume}}
ncao: inout NCAO?) { // expected-error{{'ncao' used after consume}}
nc?.b()
nc?.m()
nc?.c() // expected-note{{consumed here}}
nc?.m() // expected-note{{used here}}
nc = .none
nc?.m()
ncao?.b()
ncao?.m()
ncao?.c() // expected-note{{consumed here}}
ncao?.m() // expected-note{{used here}}
ncao = .none
ncao?.m()
}
func mutatingChains3(nc: inout NC?,
ncao: inout NCAO?) {
nc?.b()
nc?.m()
nc?.c()
nc = .none
nc?.b()
nc?.m()
ncao?.b()
ncao?.m()
ncao?.c()
ncao = .none
ncao?.b()
ncao?.m()
}
func mutatingChains4(nc: inout NC?, // expected-error{{missing reinitialization of inout parameter 'nc' after consume}}
ncao: inout NCAO?) { // expected-error{{missing reinitialization of inout parameter 'ncao' after consume}}
nc?.b()
nc?.m()
nc?.c() // expected-note{{consumed here}}
ncao?.b()
ncao?.m()
ncao?.c() // expected-note{{consumed here}}
}
func consumingChains(nc: consuming NC?, // expected-error{{'nc' used after consume}}
ncao: consuming NCAO?) { // expected-error{{'ncao' used after consume}}
nc?.b()
nc?.m()
nc?.c() // expected-note{{consumed here}}
nc?.b() // expected-note{{used here}}
nc?.m()
ncao?.b()
ncao?.m()
ncao?.c() // expected-note{{consumed here}}
ncao?.b() // expected-note{{used here}}
ncao?.m()
}
func consumingChains2(nc: consuming NC?,
ncao: consuming NCAO?) {
nc?.b()
nc?.m()
nc?.c()
ncao?.b()
ncao?.m()
ncao?.c()
}
func consumingSwitchSubject(nc: consuming NC?,
ncao: consuming NCAO?) {
switch nc?.c2() {
default:
break
}
switch ncao?.c2() {
default:
break
}
}
func consumingSwitchSubject2(nc: consuming NC?,
ncao: consuming NCAO?) {
switch nc?.c3() {
default:
break
}
switch ncao?.c3() {
default:
break
}
}
|