Skip to content

Commit 92d41ef

Browse files
committed
[Typechecker] Fix a crash
1 parent b2c8670 commit 92d41ef

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
135135
}
136136
}
137137

138-
if (cast_or_null<CallExpr>(E)) {
139-
funcCallExpr = cast<CallExpr>(E);
138+
if (auto CE = dyn_cast<CallExpr>(E)) {
139+
funcCallExpr = CE;
140140
}
141141

142142
// Check function calls, looking through implicit conversions on the
@@ -254,10 +254,13 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
254254
if (auto *tupleExpr = dyn_cast<TupleExpr>(E)) {
255255
// FIXME: Duplicate labels on enum payloads should be diagnosed
256256
// when declared, not when called.
257-
bool isEnumCase = funcCallExpr
258-
? cast_or_null<EnumElementDecl>(
259-
funcCallExpr->getCalledValue()) != nullptr
260-
: false;
257+
bool isEnumCase = false;
258+
if (funcCallExpr) {
259+
auto calledValue = funcCallExpr->getCalledValue();
260+
if (calledValue) {
261+
isEnumCase = isa<EnumElementDecl>(calledValue);
262+
}
263+
}
261264

262265
if (!funcCallExpr || isEnumCase) {
263266
auto diagnose = false;

0 commit comments

Comments
 (0)