Skip to content

Commit 7e7b6e8

Browse files
committed
ClangImporter: Fix up importSubscript() to not depend on import order
Once lazy loading supports mirrored protocol members, we can end up calling importSubscript() for a setter method before we've mirrored the getter. In this case, we call findCounterpart() with the setter, which finds the imported getter from the ProtocolDecl itself. Stop processing the potential subscript in this case, since when we later mirror the protocol member, we'll go and build it again. This should be NFC without the next change I'm working on.
1 parent 95d9aa0 commit 7e7b6e8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6585,6 +6585,13 @@ SwiftDeclConverter::importSubscript(Decl *decl,
65856585
if (!counterpart)
65866586
return nullptr;
65876587

6588+
// If we're looking at a class but the getter was found in a protocol,
6589+
// we're going to build the subscript later when we mirror the protocol
6590+
// member. Bail out here, otherwise we'll build it twice.
6591+
if (interface &&
6592+
isa<clang::ObjCProtocolDecl>(counterpart->getDeclContext()))
6593+
return nullptr;
6594+
65886595
return cast_or_null<FuncDecl>(
65896596
Impl.importDecl(counterpart, getActiveSwiftVersion()));
65906597
};

0 commit comments

Comments
 (0)