Skip to content

Commit a5694de

Browse files
committed
[TypeChecker] Don’t crash if a ExplicitCastExpr doesn’t have a cast type
If the type of an `ExplicitCastExpr` is not valid, it is a null type, which causes a crash when checking if the cast type has parameterized existentials. rdar://95629905
1 parent cc39510 commit a5694de

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3229,7 +3229,7 @@ class ExprAvailabilityWalker : public ASTWalker {
32293229
maybeDiagParameterizedExistentialErasure(EE, Where);
32303230
}
32313231
if (auto *CC = dyn_cast<ExplicitCastExpr>(E)) {
3232-
if (!isa<CoerceExpr>(CC) &&
3232+
if (!isa<CoerceExpr>(CC) && CC->getCastType() &&
32333233
CC->getCastType()->hasParameterizedExistential()) {
32343234
SourceLoc loc = CC->getCastTypeRepr() ? CC->getCastTypeRepr()->getLoc()
32353235
: E->getLoc();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
@resultBuilder
4+
struct ViewBuilder {
5+
static func buildBlock(_ x: Int) -> Int { x }
6+
}
7+
8+
func test(_: () -> Void) -> Int {
9+
return 42
10+
}
11+
12+
struct MyView {
13+
@ViewBuilder var body: Int {
14+
test {
15+
"ab" is Unknown // expected-error{{cannot find type 'Unknown' in scope}}
16+
print("x")
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)