Skip to content

Commit 971a43b

Browse files
committed
refactoring: when RangeInfo is of kind PartOfExpression, we should use the dedicated field to get the parent expression. rdar://36755861 (#14088)
1 parent 4602529 commit 971a43b

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
@@ -1686,16 +1686,25 @@ bool RefactoringActionCollapseNestedIfExpr::performChange() {
16861686
}
16871687

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

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

1698-
Expr *E = Info.ContainedNodes[0].get<Expr*>();
1707+
assert(E);
16991708

17001709
struct StringInterpolationExprFinder: public SourceEntityWalker {
17011710
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)