Skip to content

Commit 5f3a1a3

Browse files
committed
[cursorinfo] Avoid use of null raw value in enum element decl
SR-12283 rdar://59857568
1 parent b58ea4b commit 5f3a1a3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/AST/ASTWalker.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,12 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
398398
}
399399

400400
if (auto *rawLiteralExpr = ED->getRawValueUnchecked()) {
401-
Expr *newRawExpr = doIt(rawLiteralExpr);
402-
if (auto newRawLiteralExpr = dyn_cast<LiteralExpr>(newRawExpr))
403-
ED->setRawValueExpr(newRawLiteralExpr);
404-
else
401+
if (Expr *newRawExpr = doIt(rawLiteralExpr)) {
402+
auto *newLiteralRawExpr = cast<LiteralExpr>(newRawExpr);
403+
ED->setRawValueExpr(newLiteralRawExpr);
404+
} else {
405405
return true;
406+
}
406407
}
407408
return false;
408409
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
enum StringEnum: String {
2+
case foo = "foo"
3+
}
4+
5+
enum IntEnum: Int {
6+
case foo = 12
7+
}
8+
9+
// RUN: %sourcekitd-test -req=cursor -pos=2:14 %s -- %s
10+
// RUN: %sourcekitd-test -req=cursor -pos=6:14 %s -- %s

0 commit comments

Comments
 (0)