Skip to content

Commit 2107bdf

Browse files
authored
[ClangImporter] Defend against ObjC properties without getters (#17429)
Objective-C provides no way to declare such a thing, so for this to occur something else must have gone wrong. Unfortunately all we have is a SourceKit crash log, so I couldn't write a test case. Hopefully some day the assert will fire and we can handle this properly. rdar://problem/41305904
1 parent 6ed6b2f commit 2107bdf

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4891,13 +4891,18 @@ namespace {
48914891
Impl.recordImplicitUnwrapForDecl(result,
48924892
importedType.isImplicitlyUnwrapped());
48934893

4894+
// Recover from a missing getter in no-asserts builds. We're still not
4895+
// sure under what circumstances this occurs, but we shouldn't crash.
4896+
auto clangGetter = decl->getGetterMethodDecl();
4897+
assert(clangGetter && "ObjC property without getter");
4898+
if (!clangGetter)
4899+
return nullptr;
4900+
48944901
// Import the getter.
4895-
AccessorDecl *getter = nullptr;
4896-
if (auto clangGetter = decl->getGetterMethodDecl()) {
4897-
getter = importAccessor(clangGetter, result, AccessorKind::Get, dc);
4898-
if (!getter)
4899-
return nullptr;
4900-
}
4902+
AccessorDecl *getter = importAccessor(clangGetter, result,
4903+
AccessorKind::Get, dc);
4904+
if (!getter)
4905+
return nullptr;
49014906

49024907
// Import the setter, if there is one.
49034908
AccessorDecl *setter = nullptr;

0 commit comments

Comments
 (0)