Skip to content

Commit 4a94afa

Browse files
committed
[CSSimplify] Add a null check to guard against broken/missing ExpressibleByNilLiteral
I couldn't come up with an isolated test-case to add to the suite, but it's possible that `getProtocol` returns `nullptr` for invalid or missing protocol so there has to be a check for that otherwise compiler is going to crash trying to access `getDeclaredType()`. Resolves: rdar://76187450
1 parent 4de232e commit 4a94afa

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6216,8 +6216,11 @@ static CheckedCastKind getCheckedCastKind(ConstraintSystem *cs,
62166216
static bool isCastToExpressibleByNilLiteral(ConstraintSystem &cs, Type fromType,
62176217
Type toType) {
62186218
auto &ctx = cs.getASTContext();
6219-
auto *nilLiteral =
6220-
ctx.getProtocol(KnownProtocolKind::ExpressibleByNilLiteral);
6219+
auto *nilLiteral = TypeChecker::getProtocol(
6220+
ctx, SourceLoc(), KnownProtocolKind::ExpressibleByNilLiteral);
6221+
if (!nilLiteral)
6222+
return false;
6223+
62216224
return toType->isEqual(nilLiteral->getDeclaredType()) &&
62226225
fromType->getOptionalObjectType();
62236226
}

0 commit comments

Comments
 (0)