@@ -714,18 +714,20 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
714
714
// Determine whether the type was explicitly non-Sendable.
715
715
auto nominalModule = nominal->getParentModule ();
716
716
bool isExplicitlyNonSendable = nominalModule->isConcurrencyChecked () ||
717
- isExplicitSendableConformance () ||
718
717
hasExplicitSendableConformance (nominal);
719
718
720
719
// Determine whether this nominal type is visible via a @preconcurrency
721
720
// import.
722
721
auto import = findImportFor (nominal, fromDC);
723
722
724
723
// When the type is explicitly non-Sendable...
724
+ auto sourceFile = fromDC->getParentSourceFile ();
725
725
if (isExplicitlyNonSendable) {
726
- // @preconcurrency imports downgrade the diagnostic to a warning.
726
+ // @preconcurrency imports downgrade the diagnostic to a warning in Swift 6,
727
727
if (import && import ->options .contains (ImportFlags::Preconcurrency)) {
728
- // FIXME: Note that this @preconcurrency import was "used".
728
+ if (sourceFile)
729
+ sourceFile->setImportUsedPreconcurrency (*import );
730
+
729
731
return DiagnosticBehavior::Warning;
730
732
}
731
733
@@ -737,13 +739,25 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
737
739
// @preconcurrency suppresses the diagnostic in Swift 5.x, and
738
740
// downgrades it to a warning in Swift 6 and later.
739
741
if (import && import ->options .contains (ImportFlags::Preconcurrency)) {
740
- // FIXME: Note that this @preconcurrency import was "used".
742
+ if (sourceFile)
743
+ sourceFile->setImportUsedPreconcurrency (*import );
744
+
741
745
return nominalModule->getASTContext ().LangOpts .isSwiftVersionAtLeast (6 )
742
746
? DiagnosticBehavior::Warning
743
747
: DiagnosticBehavior::Ignore;
744
748
}
745
749
746
- return defaultDiagnosticBehavior ();
750
+ auto defaultBehavior = defaultDiagnosticBehavior ();
751
+
752
+ // If we are checking an implicit Sendable conformance, don't suppress
753
+ // diagnostics for declarations in the same module. We want them so make
754
+ // enclosing inferred types non-Sendable.
755
+ if (defaultBehavior == DiagnosticBehavior::Ignore &&
756
+ nominal->getParentSourceFile () &&
757
+ conformanceCheck && *conformanceCheck == SendableCheck::Implicit)
758
+ return DiagnosticBehavior::Warning;
759
+
760
+ return defaultBehavior;
747
761
}
748
762
749
763
// / Produce a diagnostic for a single instance of a non-Sendable type where
@@ -765,14 +779,6 @@ static bool diagnoseSingleNonSendableType(
765
779
766
780
bool wasSuppressed = diagnose (type, behavior);
767
781
768
- // If this type was imported from another module, try to find the
769
- // corresponding import.
770
- Optional<AttributedImport<swift::ImportedModule>> import ;
771
- SourceFile *sourceFile = fromContext.fromDC ->getParentSourceFile ();
772
- if (nominal && nominal->getParentModule () != module ) {
773
- import = findImportFor (nominal, fromContext.fromDC );
774
- }
775
-
776
782
if (behavior == DiagnosticBehavior::Ignore || wasSuppressed) {
777
783
// Don't emit any other diagnostics.
778
784
} else if (type->is <FunctionType>()) {
@@ -796,6 +802,14 @@ static bool diagnoseSingleNonSendableType(
796
802
diag::non_sendable_nominal, nominal->getDescriptiveKind (),
797
803
nominal->getName ());
798
804
805
+ // This type was imported from another module; try to find the
806
+ // corresponding import.
807
+ Optional<AttributedImport<swift::ImportedModule>> import ;
808
+ SourceFile *sourceFile = fromContext.fromDC ->getParentSourceFile ();
809
+ if (sourceFile) {
810
+ import = findImportFor (nominal, fromContext.fromDC );
811
+ }
812
+
799
813
// If we found the import that makes this nominal type visible, remark
800
814
// that it can be @preconcurrency import.
801
815
// Only emit this remark once per source file, because it can happen a
@@ -814,14 +828,6 @@ static bool diagnoseSingleNonSendableType(
814
828
}
815
829
}
816
830
817
- // If we found an import that makes this nominal type visible, and that
818
- // was a @preconcurrency import, note that we have made use of the
819
- // attribute.
820
- if (import && import ->options .contains (ImportFlags::Preconcurrency) &&
821
- sourceFile) {
822
- sourceFile->setImportUsedPreconcurrency (*import );
823
- }
824
-
825
831
return behavior == DiagnosticBehavior::Unspecified && !wasSuppressed;
826
832
}
827
833
@@ -3871,8 +3877,10 @@ static bool checkSendableInstanceStorage(
3871
3877
bool operator ()(VarDecl *property, Type propertyType) {
3872
3878
// Classes with mutable properties are not Sendable.
3873
3879
if (property->supportsMutation () && isa<ClassDecl>(nominal)) {
3874
- if (check == SendableCheck::Implicit)
3880
+ if (check == SendableCheck::Implicit) {
3881
+ invalid = true ;
3875
3882
return true ;
3883
+ }
3876
3884
3877
3885
auto behavior = SendableCheckContext (
3878
3886
dc, check).defaultDiagnosticBehavior ();
@@ -3891,6 +3899,10 @@ static bool checkSendableInstanceStorage(
3891
3899
propertyType, SendableCheckContext (dc, check), property->getLoc (),
3892
3900
[&](Type type, DiagnosticBehavior behavior) {
3893
3901
if (check == SendableCheck::Implicit) {
3902
+ // If we are to ignore this diagnose, just continue.
3903
+ if (behavior == DiagnosticBehavior::Ignore)
3904
+ return false ;
3905
+
3894
3906
invalid = true ;
3895
3907
return true ;
3896
3908
}
@@ -3918,6 +3930,10 @@ static bool checkSendableInstanceStorage(
3918
3930
elementType, SendableCheckContext (dc, check), element->getLoc (),
3919
3931
[&](Type type, DiagnosticBehavior behavior) {
3920
3932
if (check == SendableCheck::Implicit) {
3933
+ // If we are to ignore this diagnose, just continue.
3934
+ if (behavior == DiagnosticBehavior::Ignore)
3935
+ return false ;
3936
+
3921
3937
invalid = true ;
3922
3938
return true ;
3923
3939
}
0 commit comments