Skip to content

Commit f6cd19a

Browse files
committed
[Concurrency] Handle self apply exprs when computing @preconcurency in the
availability checker.
1 parent 7331c5e commit f6cd19a

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
@@ -3552,7 +3552,11 @@ class ExprAvailabilityWalker : public ASTWalker {
35523552

35533553
if (auto *apply = dyn_cast<ApplyExpr>(E)) {
35543554
bool preconcurrency = false;
3555-
auto declRef = apply->getFn()->getReferencedDecl();
3555+
auto *fn = apply->getFn();
3556+
if (auto *selfApply = dyn_cast<SelfApplyExpr>(fn)) {
3557+
fn = selfApply->getFn();
3558+
}
3559+
auto declRef = fn->getReferencedDecl();
35563560
if (auto *decl = declRef.getDecl()) {
35573561
preconcurrency = decl->preconcurrency();
35583562
}

test/Concurrency/predates_concurrency_swift6.swift

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

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

203203
class UnavailableSendable {}
204204

205205
@available(*, unavailable)
206206
extension UnavailableSendable: @unchecked Sendable {}
207-
// expected-note@-1 4 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}
207+
// expected-note@-1 8 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}
208208

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

212212
typealias T2 = RequireSendable<UnavailableSendable>
213213
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
214214

215-
func testRequirementDowngrade(ns: NotSendable, us: UnavailableSendable) {
215+
class C {
216+
@preconcurrency
217+
func requireSendable<T: Sendable>(_: T) {}
218+
219+
@preconcurrency
220+
static func requireSendableStatic<T: Sendable>(_: T) {}
221+
}
222+
223+
func testRequirementDowngrade(ns: NotSendable, us: UnavailableSendable, c: C) {
216224
requireSendable(ns)
217225
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
218226

227+
c.requireSendable(ns)
228+
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
229+
230+
C.requireSendableStatic(ns)
231+
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
232+
219233
requireSendable(us)
220234
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
235+
236+
c.requireSendable(us)
237+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
238+
239+
C.requireSendableStatic(us)
240+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
221241
}
222242

223243

@@ -232,13 +252,33 @@ func requireSendableExistential(_: any P2 & Sendable) {}
232252

233253
func requireSendableExistentialAlways(_: any P2 & Sendable) {}
234254

235-
func testErasureDowngrade(ns: NotSendable, us: UnavailableSendable) {
255+
extension C {
256+
@preconcurrency
257+
func requireSendableExistential(_: any P2 & Sendable) {}
258+
259+
@preconcurrency
260+
static func requireSendableExistentialStatic(_: any P2 & Sendable) {}
261+
}
262+
263+
func testErasureDowngrade(ns: NotSendable, us: UnavailableSendable, c: C) {
236264
requireSendableExistential(ns)
237265
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
238266

267+
c.requireSendableExistential(ns)
268+
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
269+
270+
C.requireSendableExistentialStatic(ns)
271+
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
272+
239273
requireSendableExistential(us)
240274
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
241275

276+
c.requireSendableExistential(us)
277+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
278+
279+
C.requireSendableExistentialStatic(us)
280+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
281+
242282
withSendableClosure {
243283
let ns = NotSendable()
244284
requireSendableExistentialAlways(ns)

0 commit comments

Comments
 (0)