Skip to content

Commit 1832a97

Browse files
authored
[ClangImporter] Defend against ObjC properties without getters (#17436)
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 (cherry picked from commit 2107bdf)
1 parent 0fbcf67 commit 1832a97

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
@@ -4887,13 +4887,18 @@ namespace {
48874887
Impl.recordImplicitUnwrapForDecl(result,
48884888
importedType.isImplicitlyUnwrapped());
48894889

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

48984903
// Import the setter, if there is one.
48994904
AccessorDecl *setter = nullptr;

0 commit comments

Comments
 (0)