@@ -721,10 +721,13 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
721
721
auto import = findImportFor (nominal, fromDC);
722
722
723
723
// When the type is explicitly non-Sendable...
724
+ auto sourceFile = fromDC->getParentSourceFile ();
724
725
if (isExplicitlyNonSendable) {
725
726
// @preconcurrency imports downgrade the diagnostic to a warning in Swift 6,
726
727
if (import && import ->options .contains (ImportFlags::Preconcurrency)) {
727
- // FIXME: Note that this @preconcurrency import was "used".
728
+ if (sourceFile)
729
+ sourceFile->setImportUsedPreconcurrency (*import );
730
+
728
731
return DiagnosticBehavior::Warning;
729
732
}
730
733
@@ -736,7 +739,9 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
736
739
// @preconcurrency suppresses the diagnostic in Swift 5.x, and
737
740
// downgrades it to a warning in Swift 6 and later.
738
741
if (import && import ->options .contains (ImportFlags::Preconcurrency)) {
739
- // FIXME: Note that this @preconcurrency import was "used".
742
+ if (sourceFile)
743
+ sourceFile->setImportUsedPreconcurrency (*import );
744
+
740
745
return nominalModule->getASTContext ().LangOpts .isSwiftVersionAtLeast (6 )
741
746
? DiagnosticBehavior::Warning
742
747
: DiagnosticBehavior::Ignore;
@@ -774,14 +779,6 @@ static bool diagnoseSingleNonSendableType(
774
779
775
780
bool wasSuppressed = diagnose (type, behavior);
776
781
777
- // If this type was imported from another module, try to find the
778
- // corresponding import.
779
- Optional<AttributedImport<swift::ImportedModule>> import ;
780
- SourceFile *sourceFile = fromContext.fromDC ->getParentSourceFile ();
781
- if (nominal && nominal->getParentModule () != module ) {
782
- import = findImportFor (nominal, fromContext.fromDC );
783
- }
784
-
785
782
if (behavior == DiagnosticBehavior::Ignore || wasSuppressed) {
786
783
// Don't emit any other diagnostics.
787
784
} else if (type->is <FunctionType>()) {
@@ -805,6 +802,14 @@ static bool diagnoseSingleNonSendableType(
805
802
diag::non_sendable_nominal, nominal->getDescriptiveKind (),
806
803
nominal->getName ());
807
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
+
808
813
// If we found the import that makes this nominal type visible, remark
809
814
// that it can be @preconcurrency import.
810
815
// Only emit this remark once per source file, because it can happen a
@@ -823,14 +828,6 @@ static bool diagnoseSingleNonSendableType(
823
828
}
824
829
}
825
830
826
- // If we found an import that makes this nominal type visible, and that
827
- // was a @preconcurrency import, note that we have made use of the
828
- // attribute.
829
- if (import && import ->options .contains (ImportFlags::Preconcurrency) &&
830
- sourceFile) {
831
- sourceFile->setImportUsedPreconcurrency (*import );
832
- }
833
-
834
831
return behavior == DiagnosticBehavior::Unspecified && !wasSuppressed;
835
832
}
836
833
0 commit comments