@@ -616,7 +616,7 @@ static bool shouldDiagnoseExistingDataRaces(const DeclContext *dc) {
616
616
// / Determine the default diagnostic behavior for this language mode.
617
617
static DiagnosticBehavior defaultSendableDiagnosticBehavior (
618
618
const LangOptions &langOpts) {
619
- // Prior to Swift 6, all Sendable-related diagnostics are warnings.
619
+ // Prior to Swift 6, all Sendable-related diagnostics are warnings at most .
620
620
if (!langOpts.isSwiftVersionAtLeast (6 ))
621
621
return DiagnosticBehavior::Warning;
622
622
@@ -648,6 +648,30 @@ DiagnosticBehavior SendableCheckContext::defaultDiagnosticBehavior() const {
648
648
return defaultSendableDiagnosticBehavior (fromDC->getASTContext ().LangOpts );
649
649
}
650
650
651
+ DiagnosticBehavior
652
+ SendableCheckContext::implicitSendableDiagnosticBehavior () const {
653
+ switch (fromDC->getASTContext ().LangOpts .StrictConcurrencyLevel ) {
654
+ case StrictConcurrency::Limited:
655
+ // Limited checking only diagnoses implicit Sendable within contexts that
656
+ // have adopted concurrency.
657
+ if (shouldDiagnoseExistingDataRaces (fromDC))
658
+ return DiagnosticBehavior::Warning;
659
+
660
+ LLVM_FALLTHROUGH;
661
+
662
+ case StrictConcurrency::Off:
663
+ // Explicit Sendable conformances always diagnose, even when strict
664
+ // strict checking is disabled.
665
+ if (isExplicitSendableConformance ())
666
+ return DiagnosticBehavior::Warning;
667
+
668
+ return DiagnosticBehavior::Ignore;
669
+
670
+ case StrictConcurrency::On:
671
+ return defaultDiagnosticBehavior ();
672
+ }
673
+ }
674
+
651
675
// / Determine whether the given nominal type has an explicit Sendable
652
676
// / conformance (regardless of its availability).
653
677
static bool hasExplicitSendableConformance (NominalTypeDecl *nominal,
@@ -742,10 +766,10 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
742
766
: DiagnosticBehavior::Ignore;
743
767
}
744
768
745
- auto defaultBehavior = defaultDiagnosticBehavior ();
769
+ DiagnosticBehavior defaultBehavior = implicitSendableDiagnosticBehavior ();
746
770
747
771
// If we are checking an implicit Sendable conformance, don't suppress
748
- // diagnostics for declarations in the same module. We want them so make
772
+ // diagnostics for declarations in the same module. We want them to make
749
773
// enclosing inferred types non-Sendable.
750
774
if (defaultBehavior == DiagnosticBehavior::Ignore &&
751
775
nominal->getParentSourceFile () &&
@@ -763,7 +787,7 @@ bool swift::diagnoseSendabilityErrorBasedOn(
763
787
if (nominal) {
764
788
behavior = fromContext.diagnosticBehavior (nominal);
765
789
} else {
766
- behavior = fromContext.defaultDiagnosticBehavior ();
790
+ behavior = fromContext.implicitSendableDiagnosticBehavior ();
767
791
}
768
792
769
793
bool wasSuppressed = diagnose (behavior);
0 commit comments