@@ -736,7 +736,7 @@ static bool shouldDiagnoseExistingDataRaces(const DeclContext *dc) {
736
736
// / Determine the default diagnostic behavior for this language mode.
737
737
static DiagnosticBehavior defaultSendableDiagnosticBehavior (
738
738
const LangOptions &langOpts) {
739
- // Prior to Swift 6, all Sendable-related diagnostics are warnings.
739
+ // Prior to Swift 6, all Sendable-related diagnostics are warnings at most .
740
740
if (!langOpts.isSwiftVersionAtLeast (6 ))
741
741
return DiagnosticBehavior::Warning;
742
742
@@ -768,6 +768,30 @@ DiagnosticBehavior SendableCheckContext::defaultDiagnosticBehavior() const {
768
768
return defaultSendableDiagnosticBehavior (fromDC->getASTContext ().LangOpts );
769
769
}
770
770
771
+ DiagnosticBehavior
772
+ SendableCheckContext::implicitSendableDiagnosticBehavior () const {
773
+ switch (fromDC->getASTContext ().LangOpts .StrictConcurrencyLevel ) {
774
+ case StrictConcurrency::Limited:
775
+ // Limited checking only diagnoses implicit Sendable within contexts that
776
+ // have adopted concurrency.
777
+ if (shouldDiagnoseExistingDataRaces (fromDC))
778
+ return DiagnosticBehavior::Warning;
779
+
780
+ LLVM_FALLTHROUGH;
781
+
782
+ case StrictConcurrency::Off:
783
+ // Explicit Sendable conformances always diagnose, even when strict
784
+ // strict checking is disabled.
785
+ if (isExplicitSendableConformance ())
786
+ return DiagnosticBehavior::Warning;
787
+
788
+ return DiagnosticBehavior::Ignore;
789
+
790
+ case StrictConcurrency::On:
791
+ return defaultDiagnosticBehavior ();
792
+ }
793
+ }
794
+
771
795
// / Determine whether the given nominal type has an explicit Sendable
772
796
// / conformance (regardless of its availability).
773
797
static bool hasExplicitSendableConformance (NominalTypeDecl *nominal,
@@ -862,10 +886,10 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
862
886
: DiagnosticBehavior::Ignore;
863
887
}
864
888
865
- auto defaultBehavior = defaultDiagnosticBehavior ();
889
+ DiagnosticBehavior defaultBehavior = implicitSendableDiagnosticBehavior ();
866
890
867
891
// If we are checking an implicit Sendable conformance, don't suppress
868
- // diagnostics for declarations in the same module. We want them so make
892
+ // diagnostics for declarations in the same module. We want them to make
869
893
// enclosing inferred types non-Sendable.
870
894
if (defaultBehavior == DiagnosticBehavior::Ignore &&
871
895
nominal->getParentSourceFile () &&
@@ -883,7 +907,7 @@ bool swift::diagnoseSendabilityErrorBasedOn(
883
907
if (nominal) {
884
908
behavior = fromContext.diagnosticBehavior (nominal);
885
909
} else {
886
- behavior = fromContext.defaultDiagnosticBehavior ();
910
+ behavior = fromContext.implicitSendableDiagnosticBehavior ();
887
911
}
888
912
889
913
bool wasSuppressed = diagnose (behavior);
0 commit comments