Skip to content

Commit 447bf8c

Browse files
committed
[Async Refactoring] Add missing null type check
Don't crash if we have a boolean condition without a type, as that may occur in invalid code. rdar://79864182
1 parent dcd2ddb commit 447bf8c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4521,7 +4521,8 @@ struct CallbackCondition {
45214521

45224522
/// A bool condition expression.
45234523
explicit CallbackCondition(const Expr *E) {
4524-
if (!E->getType()->isBool())
4524+
// FIXME: Sema should produce ErrorType.
4525+
if (!E->getType() || !E->getType()->isBool())
45254526
return;
45264527

45274528
auto CondType = ConditionType::IS_TRUE;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func callbackIntWithError(_ completion: (Int8, Error?) -> Void) {}
2+
3+
// rdar://79864182
4+
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=INVALID-COND %s
5+
callbackIntWithError { x, err in
6+
if x {
7+
print("ok")
8+
}
9+
}
10+
// INVALID-COND: let x = try await callbackIntWithError()
11+
// INVALID-COND-NEXT: if x {
12+
// INVALID-COND-NEXT: print("ok")
13+
// INVALID-COND-NEXT: }
14+

0 commit comments

Comments
 (0)