@@ -726,10 +726,13 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
726
726
auto import = findImportFor (nominal, fromDC);
727
727
728
728
// When the type is explicitly non-Sendable...
729
+ auto sourceFile = fromDC->getParentSourceFile ();
729
730
if (isExplicitlyNonSendable) {
730
731
// @preconcurrency imports downgrade the diagnostic to a warning in Swift 6,
731
732
if (import && import ->options .contains (ImportFlags::Preconcurrency)) {
732
- // FIXME: Note that this @preconcurrency import was "used".
733
+ if (sourceFile)
734
+ sourceFile->setImportUsedPreconcurrency (*import );
735
+
733
736
return DiagnosticBehavior::Warning;
734
737
}
735
738
@@ -741,7 +744,9 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
741
744
// @preconcurrency suppresses the diagnostic in Swift 5.x, and
742
745
// downgrades it to a warning in Swift 6 and later.
743
746
if (import && import ->options .contains (ImportFlags::Preconcurrency)) {
744
- // FIXME: Note that this @preconcurrency import was "used".
747
+ if (sourceFile)
748
+ sourceFile->setImportUsedPreconcurrency (*import );
749
+
745
750
return nominalModule->getASTContext ().LangOpts .isSwiftVersionAtLeast (6 )
746
751
? DiagnosticBehavior::Warning
747
752
: DiagnosticBehavior::Ignore;
@@ -779,14 +784,6 @@ static bool diagnoseSingleNonSendableType(
779
784
780
785
bool wasSuppressed = diagnose (type, behavior);
781
786
782
- // If this type was imported from another module, try to find the
783
- // corresponding import.
784
- Optional<AttributedImport<swift::ImportedModule>> import ;
785
- SourceFile *sourceFile = fromContext.fromDC ->getParentSourceFile ();
786
- if (nominal && nominal->getParentModule () != module ) {
787
- import = findImportFor (nominal, fromContext.fromDC );
788
- }
789
-
790
787
if (behavior == DiagnosticBehavior::Ignore || wasSuppressed) {
791
788
// Don't emit any other diagnostics.
792
789
} else if (type->is <FunctionType>()) {
@@ -810,6 +807,14 @@ static bool diagnoseSingleNonSendableType(
810
807
diag::non_sendable_nominal, nominal->getDescriptiveKind (),
811
808
nominal->getName ());
812
809
810
+ // This type was imported from another module; try to find the
811
+ // corresponding import.
812
+ Optional<AttributedImport<swift::ImportedModule>> import ;
813
+ SourceFile *sourceFile = fromContext.fromDC ->getParentSourceFile ();
814
+ if (sourceFile) {
815
+ import = findImportFor (nominal, fromContext.fromDC );
816
+ }
817
+
813
818
// If we found the import that makes this nominal type visible, remark
814
819
// that it can be @preconcurrency import.
815
820
// Only emit this remark once per source file, because it can happen a
@@ -828,14 +833,6 @@ static bool diagnoseSingleNonSendableType(
828
833
}
829
834
}
830
835
831
- // If we found an import that makes this nominal type visible, and that
832
- // was a @preconcurrency import, note that we have made use of the
833
- // attribute.
834
- if (import && import ->options .contains (ImportFlags::Preconcurrency) &&
835
- sourceFile) {
836
- sourceFile->setImportUsedPreconcurrency (*import );
837
- }
838
-
839
836
return behavior == DiagnosticBehavior::Unspecified && !wasSuppressed;
840
837
}
841
838
0 commit comments