Skip to content

[4.1] refactoring: when RangeInfo is of kind PartOfExpression, we should use the dedicated field to get the parent expression. rdar://36755861 #14089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/IDE/Refactoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1686,16 +1686,25 @@ bool RefactoringActionCollapseNestedIfExpr::performChange() {
}

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

// FIXME: We should always have a valid node.
if (Info.ContainedNodes.empty())
switch (Info.Kind) {
case RangeKind::SingleExpression:
// FIXME: the range info kind should imply non-empty list.
if (!Info.ContainedNodes.empty())
E = Info.ContainedNodes[0].get<Expr*>();
else
return nullptr;
break;
case RangeKind::PartOfExpression:
E = Info.CommonExprParent;
break;
default:
return nullptr;
}

Expr *E = Info.ContainedNodes[0].get<Expr*>();
assert(E);

struct StringInterpolationExprFinder: public SourceEntityWalker {
std::unique_ptr<llvm::SetVector<Expr*>> Bucket = llvm::
Expand Down
11 changes: 11 additions & 0 deletions test/refactoring/RefactoringKind/crashers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// rdar://36755861
func doit(_: ()->()) {}
struct S {}
func foo() {
doit {
let s = S()
}
}

// RUN: %refactor -source-filename %s -pos=6:5 -end-pos=6:13 | %FileCheck %s -check-prefix=CHECK1
// CHECK1: Action begins