Skip to content

Commit 70afb73

Browse files
author
Gabor Horvath
committed
[cxx-interop] Fix unqualified name lookup failure
When MemberImportVisibility is enabled we failed to find certain base methods from the extensions when said base methods are imported from C++. rdar://154887575
1 parent 31408fe commit 70afb73

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lib/AST/NameLookup.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,15 @@ static bool isAcceptableLookupResult(const DeclContext *dc, NLOptions options,
24232423
// Check that there is some import in the originating context that makes
24242424
// this decl visible.
24252425
if (!(options & NL_IgnoreMissingImports)) {
2426-
if (!dc->isDeclImported(decl))
2426+
bool isFromClangModule = false;
2427+
auto definingModule = decl->getModuleContextForNameLookup();
2428+
if (dc->getASTContext().LangOpts.EnableCXXInterop) {
2429+
if (definingModule->isClangHeaderImportModule())
2430+
isFromClangModule = true;
2431+
}
2432+
// dc->isDeclImported(decl) false even when the correct clang module is
2433+
// imported.
2434+
if (!dc->isDeclImported(decl) && !isFromClangModule)
24272435
return false;
24282436
}
24292437

test/Interop/Cxx/class/inheritance/Inputs/inherited-lookup.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ struct IIOne : IOne {
1616
struct IIIOne : IIOne {
1717
int methodIII(void) const { return -111; }
1818
};
19+
20+
class Base {
21+
public:
22+
bool baseMethod() const { return true; }
23+
};
24+
25+
namespace Bar {
26+
class Derived : public Base {};
27+
} // namespace Bar

test/Interop/Cxx/class/inheritance/inherited-lookup-executable.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -cxx-interoperability-mode=default)
1+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -cxx-interoperability-mode=default -enable-upcoming-feature MemberImportVisibility)
22
//
33
// REQUIRES: executable_test
44
import InheritedLookup
@@ -62,4 +62,15 @@ InheritedMemberTestSuite.test("Eagerly imported methods resolve to base classes"
6262
expectEqual(iiiOne[0], 1)
6363
}
6464

65+
extension Bar.Derived {
66+
public func callBase() {
67+
let _ = baseMethod()
68+
}
69+
}
70+
71+
InheritedMemberTestSuite.test("Look up base methods from extensions") {
72+
let a = Bar.Derived()
73+
a.callBase()
74+
}
75+
6576
runAllTests()

0 commit comments

Comments
 (0)