Skip to content

Commit d3281ce

Browse files
committed
Stop reimport of func decl
1 parent b897654 commit d3281ce

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4982,7 +4982,7 @@ ValueDecl *cloneBaseMemberDecl(ValueDecl *decl, DeclContext *newContext) {
49824982
// support these we need to tell Swift to type check the synthesized bodies.
49834983
// TODO: we also currently don't support static functions. That shouldn't be
49844984
// too hard.
4985-
if (fn->isStatic() ||
4985+
if (fn->isStatic() || cast<clang::FunctionDecl>(fn->getClangDecl())->isOverloadedOperator() ||
49864986
(fn->getClangDecl() &&
49874987
isa<clang::FunctionTemplateDecl>(fn->getClangDecl())))
49884988
return nullptr;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,13 @@ namespace {
27722772
if (!dc)
27732773
return nullptr;
27742774

2775+
// We may have already imported this function decl before we imported the
2776+
// parent record. In such a case it's important we don't re-import.
2777+
auto known = Impl.ImportedDecls.find({decl, getVersion()});
2778+
if (known != Impl.ImportedDecls.end()) {
2779+
return known->second;
2780+
}
2781+
27752782
bool isOperator = decl->getDeclName().getNameKind() ==
27762783
clang::DeclarationName::CXXOperatorName;
27772784
bool isNonSubscriptOperator =

test/Interop/Cxx/operators/member-inline.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import StdlibUnittest
88
var OperatorsTestSuite = TestSuite("Operators")
99

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

@@ -257,6 +257,14 @@ OperatorsTestSuite.test("PtrToPtr.subscript (inline)") {
257257
expectEqual(23, arr[0]![0]![0])
258258
}
259259

260+
OperatorsTestSuite.test("AddressOnlyIntWrapper.minus") {
261+
let lhs = AddressOnlyIntWrapper(42)
262+
let rhs = AddressOnlyIntWrapper(23)
263+
264+
let result = lhs - rhs
265+
expectEqual(19, result.value)
266+
}
267+
260268
// TODO: this causes a crash (does it also crash on main?)
261269
//OperatorsTestSuite.test("TemplatedSubscriptArrayByVal.subscript (inline)") {
262270
// let ptr: UnsafeMutablePointer<Int32> =

0 commit comments

Comments
 (0)