Skip to content

[CXX Interoperability] Stop re-importing FuncDecl when FuncDecl is imported before parent record #59607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,13 @@ namespace {
if (!dc)
return nullptr;

// We may have already imported this function decl before we imported the
// parent record. In such a case it's important we don't re-import.
auto known = Impl.ImportedDecls.find({decl, getVersion()});
if (known != Impl.ImportedDecls.end()) {
return known->second;
}

bool isOperator = decl->getDeclName().getNameKind() ==
clang::DeclarationName::CXXOperatorName;
bool isNonSubscriptOperator =
Expand Down
3 changes: 3 additions & 0 deletions test/Interop/Cxx/operators/Inputs/member-inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct AddressOnlyIntWrapper {
return value + x * y;
}

AddressOnlyIntWrapper operator-(AddressOnlyIntWrapper rhs) const {
return AddressOnlyIntWrapper(value - rhs.value);
}
AddressOnlyIntWrapper &operator++() {
value++;
return *this;
Expand Down
11 changes: 10 additions & 1 deletion test/Interop/Cxx/operators/member-inline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@ import StdlibUnittest
var OperatorsTestSuite = TestSuite("Operators")

#if !os(Windows) // SR-13129
OperatorsTestSuite.test("LoadableIntWrapper.plus (inline)") {
OperatorsTestSuite.test("LoadableIntWrapper.minus (inline)") {
var lhs = LoadableIntWrapper(value: 42)
let rhs = LoadableIntWrapper(value: 23)

let result = lhs - rhs

expectEqual(19, result.value)
}

OperatorsTestSuite.test("AddressOnlyIntWrapper.minus") {
let lhs = AddressOnlyIntWrapper(42)
let rhs = AddressOnlyIntWrapper(23)

let result = lhs - rhs

expectEqual(19, result.value)
}
#endif

OperatorsTestSuite.test("LoadableIntWrapper.call (inline)") {
Expand Down