Skip to content

Commit e8d9804

Browse files
Merge pull request swiftlang#77057 from sophiapoirier/preconcurrency_import_warning_for_suppressed_sendable_diagnostic
[Concurrency] fix erroneous "@preconcurrency import" diagnostic
2 parents 8f66bf1 + 84eaee4 commit e8d9804

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4263,13 +4263,17 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
42634263
diagnoseSendabilityErrorBasedOn(conformance->getProtocol(), sendFrom,
42644264
[&](DiagnosticBehavior limit) {
42654265
auto &diags = DC->getASTContext().Diags;
4266-
diags.diagnose(getLocForDiagnosingWitness(conformance, witness),
4267-
diag::witness_not_as_sendable,
4268-
witness, conformance->getProtocol())
4266+
auto preconcurrencyBehaviorLimit =
4267+
sendFrom.preconcurrencyBehavior(nominal);
4268+
diags
4269+
.diagnose(getLocForDiagnosingWitness(conformance, witness),
4270+
diag::witness_not_as_sendable, witness,
4271+
conformance->getProtocol())
42694272
.limitBehaviorUntilSwiftVersion(limit, 6)
4270-
.limitBehaviorIf(sendFrom.preconcurrencyBehavior(nominal));
4273+
.limitBehaviorIf(preconcurrencyBehaviorLimit);
42714274
diags.diagnose(requirement, diag::less_sendable_reqt_here);
4272-
return false;
4275+
return preconcurrencyBehaviorLimit &&
4276+
(*preconcurrencyBehaviorLimit == DiagnosticBehavior::Ignore);
42734277
});
42744278
});
42754279
}

test/Concurrency/sendable_conformance_checking.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,16 @@ public struct TestSendableWitnesses2 : NoSendableReqs {
204204
var prop = globalFn // Ok (no warnings)
205205
static let staticProp = globalFn // Ok (no warnings)
206206
}
207+
208+
// @preconcurrency attributes to make it akin to an imported Obj-C API
209+
@preconcurrency @MainActor public protocol EscapingSendableProtocol {
210+
// expected-complete-and-tns-note @+1 {{protocol requires function 'f(handler:)' with type '(@escaping @MainActor @Sendable (Int) -> Void) -> ()'}}
211+
@preconcurrency func f(handler: @escaping @MainActor @Sendable (Int) -> Void)
212+
}
213+
214+
// expected-complete-and-tns-error @+2 {{type 'TestEscapingOnly' does not conform to protocol 'EscapingSendableProtocol'}}
215+
// expected-complete-and-tns-note @+1 {{add stubs for conformance}}
216+
class TestEscapingOnly: EscapingSendableProtocol {
217+
// expected-complete-and-tns-note @+1 {{candidate has non-matching type '(@escaping (Int) -> Void) -> ()'}}
218+
func f(handler: @escaping (Int) -> Void) {}
219+
}

0 commit comments

Comments
 (0)