Skip to content

Commit 58c62eb

Browse files
committed
Look at transitive imports when checking for @_predatesConcurrency imports
1 parent 7552cf9 commit 58c62eb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/Strings.h"
2121
#include "swift/AST/ASTWalker.h"
2222
#include "swift/AST/GenericEnvironment.h"
23+
#include "swift/AST/ImportCache.h"
2324
#include "swift/AST/Initializer.h"
2425
#include "swift/AST/ParameterList.h"
2526
#include "swift/AST/ProtocolConformance.h"
@@ -686,11 +687,23 @@ static Optional<AttributedImport<ImportedModule>> findImportFor(
686687
if (!fromSourceFile)
687688
return None;
688689

690+
// Look to see if the owning module was directly imported.
689691
for (const auto &import : fromSourceFile->getImports()) {
690692
if (import.module.importedModule == nominalModule)
691693
return import;
692694
}
693695

696+
// Now look for transitive imports.
697+
auto &importCache = nominal->getASTContext().getImportCache();
698+
for (const auto &import : fromSourceFile->getImports()) {
699+
auto &importSet = importCache.getImportSet(import.module.importedModule);
700+
for (const auto &transitive : importSet.getTransitiveImports()) {
701+
if (transitive.importedModule == nominalModule) {
702+
return import;
703+
}
704+
}
705+
}
706+
694707
return None;
695708
}
696709

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// FIXME: BEGIN -enable-source-import hackaround
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules %s -verify -swift-version 6
5+
6+
// REQUIRES: objc_interop
7+
// REQUIRES: concurrency
8+
// REQUIRES: asserts
9+
10+
@_predatesConcurrency import Foundation
11+
12+
func acceptSendable<T: Sendable>(_: T) { }
13+
14+
func useSendable(ns: NSString) {
15+
// Note: warning below is downgraded due to @_predatesConcurrency
16+
acceptSendable(ns) // expected-warning{{type 'NSString' does not conform to the 'Sendable' protocol}}
17+
}

0 commit comments

Comments
 (0)