Skip to content

Fold upstream Migrator changes into swift-4.0-branch #10466

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 1 addition & 11 deletions lib/Migrator/TupleSplatMigratorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,10 @@ struct TupleSplatMigratorPass : public ASTMigratorPass,
}

unsigned ClosureArity = Closure->getParameters()->size();
if (NativeArity == ClosureArity)
if (NativeArity <= ClosureArity)
return false;

ShorthandFinder Finder(Closure);
if (NativeArity == 1 && ClosureArity > 1) {
// Prepend $0. to existing references
Finder.forEachReference([this](Expr *Ref, ParamDecl* Def) {
if (auto *TE = dyn_cast<TupleElementExpr>(Ref))
Ref = TE->getBase();
SourceLoc AfterDollar = Ref->getStartLoc().getAdvancedLoc(1);
Editor.insert(AfterDollar, "0.");
});
return true;
}

if (ClosureArity == 1 && NativeArity > 1) {
// Remove $0. from existing references or if it's only $0, replace it
Expand Down
6 changes: 3 additions & 3 deletions test/Migrator/tuple-arguments.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ func toString(indexes: Int?...) -> String {
})
let _ = indexes.reduce(0) { print(($0, $1)); return $0 + ($1 ?? 0)}
let _ = indexes.reduce(0) { (true ? ($0, $1) : (1, 2)).0 + ($1 ?? 0) }
let _ = [(1, 2)].contains { $0.0 != $0.1 }
let _ = [(1, 2)].contains { $0 != $1 }
_ = ["Hello", "Foo"].sorted { print(($0, $1)); return $0.characters.count > $1.characters.count }
_ = ["Hello" : 2].map { ($0.0, ($0.1)) }
_ = ["Hello" : 2].map { ($0, ($1)) }
}

extension Dictionary {
public mutating func merge(with dictionary: Dictionary) {
dictionary.forEach { updateValue($0.1, forKey: $0.0) }
dictionary.forEach { updateValue($1, forKey: $0) }
}
}

Expand Down