Skip to content

Commit cf36346

Browse files
authored
refactoring: when RangeInfo is of kind PartOfExpression, we should use the dedicated field to get the parent expression. rdar://36755861 (#14088)
1 parent 689ddaa commit cf36346

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,16 +1684,25 @@ bool RefactoringActionCollapseNestedIfExpr::performChange() {
16841684
}
16851685

16861686
static std::unique_ptr<llvm::SetVector<Expr*>>
1687-
findConcatenatedExpressions(ResolvedRangeInfo Info, ASTContext &Ctx) {
1688-
if (Info.Kind != RangeKind::SingleExpression
1689-
&& Info.Kind != RangeKind::PartOfExpression)
1690-
return nullptr;
1687+
findConcatenatedExpressions(ResolvedRangeInfo Info, ASTContext &Ctx) {
1688+
Expr *E = nullptr;
16911689

1692-
// FIXME: We should always have a valid node.
1693-
if (Info.ContainedNodes.empty())
1690+
switch (Info.Kind) {
1691+
case RangeKind::SingleExpression:
1692+
// FIXME: the range info kind should imply non-empty list.
1693+
if (!Info.ContainedNodes.empty())
1694+
E = Info.ContainedNodes[0].get<Expr*>();
1695+
else
1696+
return nullptr;
1697+
break;
1698+
case RangeKind::PartOfExpression:
1699+
E = Info.CommonExprParent;
1700+
break;
1701+
default:
16941702
return nullptr;
1703+
}
16951704

1696-
Expr *E = Info.ContainedNodes[0].get<Expr*>();
1705+
assert(E);
16971706

16981707
struct StringInterpolationExprFinder: public SourceEntityWalker {
16991708
std::unique_ptr<llvm::SetVector<Expr*>> Bucket = llvm::
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// rdar://36755861
2+
func doit(_: ()->()) {}
3+
struct S {}
4+
func foo() {
5+
doit {
6+
let s = S()
7+
}
8+
}
9+
10+
// RUN: %refactor -source-filename %s -pos=6:5 -end-pos=6:13 | %FileCheck %s -check-prefix=CHECK1
11+
// CHECK1: Action begins

0 commit comments

Comments
 (0)