Skip to content

Commit 810a98c

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 6ca531c commit 810a98c

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
@@ -2668,9 +2668,11 @@ ImportDeclRequest::evaluate(Evaluator &evaluator, const SourceFile *sf,
26682668
auto &ctx = sf->getASTContext();
26692669
auto imports = sf->getImports();
26702670

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

@@ -2679,7 +2681,8 @@ ImportDeclRequest::evaluate(Evaluator &evaluator, const SourceFile *sf,
26792681
for (const auto &import : imports) {
26802682
auto &importSet = importCache.getImportSet(import.module.importedModule);
26812683
for (const auto &transitive : importSet.getTransitiveImports()) {
2682-
if (transitive.importedModule == module) {
2684+
if (transitive.importedModule
2685+
->isSameModuleLookingThroughOverlays(mutModule)) {
26832686
return import;
26842687
}
26852688
}
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)