Skip to content

Commit e0ce5fc

Browse files
committed
[TypeChecker] Fix crash with Objective C keypaths.
We have a crash reported but do not have a test case and my attempt at creating one was unsuccessful. It seems like the issue is that we have an invalid decl that we attempt to access the interface type on, though, so hopefully this fixes the issue. I also tweaked the constraint generator to bail out when checkObjCKeyPathExpr fails. Potentially fixes: rdar://problem/40955755
1 parent c6acfbb commit e0ce5fc

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/Sema/CSGen.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -3280,7 +3280,8 @@ namespace {
32803280
if (auto keyPath = dyn_cast<KeyPathExpr>(expr)) {
32813281
if (keyPath->isObjC()) {
32823282
auto &cs = CG.getConstraintSystem();
3283-
(void)cs.getTypeChecker().checkObjCKeyPathExpr(cs.DC, keyPath);
3283+
if (!cs.getTypeChecker().checkObjCKeyPathExpr(cs.DC, keyPath))
3284+
return { false, nullptr };
32843285
}
32853286
}
32863287

lib/Sema/TypeCheckExprObjC.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -317,6 +317,8 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
317317
// Handle property references.
318318
if (auto var = dyn_cast<VarDecl>(found)) {
319319
validateDecl(var);
320+
if (var->isInvalid() || !var->hasInterfaceType())
321+
return None;
320322

321323
// Resolve this component to the variable we found.
322324
auto varRef = ConcreteDeclRef(var);

0 commit comments

Comments
 (0)