@@ -835,41 +835,47 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
835
835
}
836
836
837
837
std::optional<DiagnosticBehavior>
838
- SendableCheckContext::preconcurrencyBehavior (Decl *decl) const {
839
- if (!decl)
840
- return std::nullopt;
838
+ swift::getConcurrencyDiagnosticBehaviorLimit (NominalTypeDecl *nominal,
839
+ const DeclContext *fromDC) {
840
+ ModuleDecl *importedModule = nullptr ;
841
+ if (nominal->getAttrs ().hasAttribute <PreconcurrencyAttr>()) {
842
+ // If the declaration itself has the @preconcurrency attribute,
843
+ // respect it.
844
+ importedModule = nominal->getParentModule ();
845
+ } else {
846
+ // Determine whether this nominal type is visible via a @preconcurrency
847
+ // import.
848
+ auto import = nominal->findImport (fromDC);
849
+ auto sourceFile = fromDC->getParentSourceFile ();
841
850
842
- if (auto *nominal = dyn_cast<NominalTypeDecl>(decl)) {
843
- ModuleDecl *importedModule = nullptr ;
844
- if (nominal->getAttrs ().hasAttribute <PreconcurrencyAttr>()) {
845
- // If the declaration itself has the @preconcurrency attribute,
846
- // respect it.
847
- importedModule = nominal->getParentModule ();
848
- } else {
849
- // Determine whether this nominal type is visible via a @preconcurrency
850
- // import.
851
- auto import = nominal->findImport (fromDC);
852
- auto sourceFile = fromDC->getParentSourceFile ();
851
+ if (!import || !import ->options .contains (ImportFlags::Preconcurrency))
852
+ return std::nullopt;
853
853
854
- if (! import || ! import -> options . contains (ImportFlags::Preconcurrency) )
855
- return std::nullopt ;
854
+ if (sourceFile )
855
+ sourceFile-> setImportUsedPreconcurrency (* import ) ;
856
856
857
- if (sourceFile)
858
- sourceFile-> setImportUsedPreconcurrency (* import );
857
+ importedModule = import -> module . importedModule ;
858
+ }
859
859
860
- importedModule = import ->module .importedModule ;
861
- }
860
+ // When the type is explicitly non-Sendable, @preconcurrency imports
861
+ // downgrade the diagnostic to a warning in Swift 6.
862
+ if (hasExplicitSendableConformance (nominal))
863
+ return DiagnosticBehavior::Warning;
862
864
863
- // When the type is explicitly non-Sendable, @preconcurrency imports
864
- // downgrade the diagnostic to a warning in Swift 6.
865
- if (hasExplicitSendableConformance (nominal))
866
- return DiagnosticBehavior::Warning;
865
+ // When the type is implicitly non-Sendable, `@preconcurrency` suppresses
866
+ // diagnostics until the imported module enables Swift 6.
867
+ return importedModule->isConcurrencyChecked ()
868
+ ? DiagnosticBehavior::Warning
869
+ : DiagnosticBehavior::Ignore;
870
+ }
871
+
872
+ std::optional<DiagnosticBehavior>
873
+ SendableCheckContext::preconcurrencyBehavior (Decl *decl) const {
874
+ if (!decl)
875
+ return std::nullopt;
867
876
868
- // When the type is implicitly non-Sendable, `@preconcurrency` suppresses
869
- // diagnostics until the imported module enables Swift 6.
870
- return importedModule->isConcurrencyChecked ()
871
- ? DiagnosticBehavior::Warning
872
- : DiagnosticBehavior::Ignore;
877
+ if (auto *nominal = dyn_cast<NominalTypeDecl>(decl)) {
878
+ return getConcurrencyDiagnosticBehaviorLimit (nominal, fromDC);
873
879
}
874
880
875
881
return std::nullopt;
0 commit comments