Skip to content

Commit 4dbc06e

Browse files
committed
[Concurrency] Handle self apply exprs when computing @preconcurency in the
availability checker. (cherry picked from commit f6cd19a)
1 parent 899f785 commit 4dbc06e

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3473,7 +3473,11 @@ class ExprAvailabilityWalker : public ASTWalker {
34733473

34743474
if (auto *apply = dyn_cast<ApplyExpr>(E)) {
34753475
bool preconcurrency = false;
3476-
auto declRef = apply->getFn()->getReferencedDecl();
3476+
auto *fn = apply->getFn();
3477+
if (auto *selfApply = dyn_cast<SelfApplyExpr>(fn)) {
3478+
fn = selfApply->getFn();
3479+
}
3480+
auto declRef = fn->getReferencedDecl();
34773481
if (auto *decl = declRef.getDecl()) {
34783482
preconcurrency = decl->preconcurrency();
34793483
}

test/Concurrency/predates_concurrency_swift6.swift

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,46 @@ func requireSendable<T: Sendable>(_: T) {}
180180
@preconcurrency
181181
struct RequireSendable<T: Sendable> {}
182182

183-
class NotSendable {} // expected-note 4 {{class 'NotSendable' does not conform to the 'Sendable' protocol}}
183+
class NotSendable {} // expected-note 8 {{class 'NotSendable' does not conform to the 'Sendable' protocol}}
184184

185185
class UnavailableSendable {}
186186

187187
@available(*, unavailable)
188188
extension UnavailableSendable: @unchecked Sendable {}
189-
// expected-note@-1 4 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}
189+
// expected-note@-1 8 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}
190190

191191
typealias T = RequireSendable<NotSendable>
192192
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
193193

194194
typealias T2 = RequireSendable<UnavailableSendable>
195195
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
196196

197-
func testRequirementDowngrade(ns: NotSendable, us: UnavailableSendable) {
197+
class C {
198+
@preconcurrency
199+
func requireSendable<T: Sendable>(_: T) {}
200+
201+
@preconcurrency
202+
static func requireSendableStatic<T: Sendable>(_: T) {}
203+
}
204+
205+
func testRequirementDowngrade(ns: NotSendable, us: UnavailableSendable, c: C) {
198206
requireSendable(ns)
199207
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
200208

209+
c.requireSendable(ns)
210+
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
211+
212+
C.requireSendableStatic(ns)
213+
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
214+
201215
requireSendable(us)
202216
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
217+
218+
c.requireSendable(us)
219+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
220+
221+
C.requireSendableStatic(us)
222+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
203223
}
204224

205225

@@ -214,13 +234,33 @@ func requireSendableExistential(_: any P2 & Sendable) {}
214234

215235
func requireSendableExistentialAlways(_: any P2 & Sendable) {}
216236

217-
func testErasureDowngrade(ns: NotSendable, us: UnavailableSendable) {
237+
extension C {
238+
@preconcurrency
239+
func requireSendableExistential(_: any P2 & Sendable) {}
240+
241+
@preconcurrency
242+
static func requireSendableExistentialStatic(_: any P2 & Sendable) {}
243+
}
244+
245+
func testErasureDowngrade(ns: NotSendable, us: UnavailableSendable, c: C) {
218246
requireSendableExistential(ns)
219247
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
220248

249+
c.requireSendableExistential(ns)
250+
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
251+
252+
C.requireSendableExistentialStatic(ns)
253+
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
254+
221255
requireSendableExistential(us)
222256
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
223257

258+
c.requireSendableExistential(us)
259+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
260+
261+
C.requireSendableExistentialStatic(us)
262+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
263+
224264
withSendableClosure {
225265
let ns = NotSendable()
226266
requireSendableExistentialAlways(ns)

0 commit comments

Comments
 (0)