Skip to content

Commit f555f71

Browse files
committed
Teach "find imports" to equate overlay modules with their underlying modules
The operation that finds the best import for a given declaration was treating an overload module as being distinct from its underlying module, even though they both have the same name and are imported together. Teach it to treat those modules as equivalent, so we correctly identify the right import declaration for something that comes from the underlying module. Fixes rdar://129401319.
1 parent 332d23e commit f555f71

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/AST/Module.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,9 +2667,11 @@ ImportDeclRequest::evaluate(Evaluator &evaluator, const SourceFile *sf,
26672667
auto &ctx = sf->getASTContext();
26682668
auto imports = sf->getImports();
26692669

2670+
auto mutModule = const_cast<ModuleDecl *>(module);
26702671
// Look to see if the owning module was directly imported.
26712672
for (const auto &import : imports) {
2672-
if (import.module.importedModule == module)
2673+
if (import.module.importedModule
2674+
->isSameModuleLookingThroughOverlays(mutModule))
26732675
return import;
26742676
}
26752677

@@ -2678,7 +2680,8 @@ ImportDeclRequest::evaluate(Evaluator &evaluator, const SourceFile *sf,
26782680
for (const auto &import : imports) {
26792681
auto &importSet = importCache.getImportSet(import.module.importedModule);
26802682
for (const auto &transitive : importSet.getTransitiveImports()) {
2681-
if (transitive.importedModule == module) {
2683+
if (transitive.importedModule
2684+
->isSameModuleLookingThroughOverlays(mutModule)) {
26822685
return import;
26832686
}
26842687
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -swift-version 6 -I %t %s -emit-sil -o /dev/null -verify -parse-as-library
4+
5+
// REQUIRES: OS=macosx
6+
7+
import Foundation
8+
@preconcurrency import Darwin
9+
10+
func mach_task_self() -> mach_port_t {
11+
return mach_task_self_
12+
}

0 commit comments

Comments
 (0)