Skip to content

Commit 59edbdf

Browse files
authored
Merge pull request #14999 from nkcsgexi/fix-refactoring-crash-init-null
2 parents 7b3290c + 2f47af6 commit 59edbdf

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,8 +1884,11 @@ class ExpandableBindingTernaryExprInfo: public ExpandableTernaryExprInfo {
18841884
Binding(Binding) {}
18851885

18861886
IfExpr *getIf() {
1887-
if (Binding && Binding->getNumPatternEntries() == 1)
1888-
return dyn_cast<IfExpr>(Binding->getInit(0));
1887+
if (Binding && Binding->getNumPatternEntries() == 1) {
1888+
if (auto *Init = Binding->getInit(0)) {
1889+
return dyn_cast<IfExpr>(Init);
1890+
}
1891+
}
18891892

18901893
return nullptr;
18911894
}

test/refactoring/RefactoringKind/crashers.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ func foo() {
55
doit {
66
let s = S()
77
}
8+
var a: Int
89
}
910

1011
// RUN: %refactor -source-filename %s -pos=6:5 -end-pos=6:13 | %FileCheck %s -check-prefix=CHECK1
12+
// RUN: %refactor -source-filename %s -pos=8:1 -end-pos=8:13 | %FileCheck %s -check-prefix=CHECK1
1113
// CHECK1: Action begins

0 commit comments

Comments
 (0)