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