Merge pull request #10011 from CodaFi/code-covfeferage
[4.0] Add a size heuristic to the Space Engine
diff --git a/lib/Migrator/TupleSplatMigratorPass.cpp b/lib/Migrator/TupleSplatMigratorPass.cpp
index 2aedb1e..f998480 100644
--- a/lib/Migrator/TupleSplatMigratorPass.cpp
+++ b/lib/Migrator/TupleSplatMigratorPass.cpp
@@ -254,7 +254,15 @@
}
}
- Editor.replaceToken(closureE->getInLoc(), "= $0;");
+ // If the original closure was a single expression without the need
+ // for a `return` statement, it needs one now, because we've added a new
+ // assignment statement just above.
+ if (closureE->hasSingleExpressionBody()) {
+ Editor.replaceToken(closureE->getInLoc(), "= $0; return");
+ } else {
+ Editor.replaceToken(closureE->getInLoc(), "= $0;");
+ }
+
return true;
}
@@ -293,7 +301,11 @@
auto param = paramList->get(i);
OS << param->getNameStr();
}
- OS << ") = __val; ";
+ OS << ") = __val;";
+
+ if (closureE->hasSingleExpressionBody()) {
+ OS << " return";
+ }
}
Editor.replace(paramList->getSourceRange(), paramListText);
diff --git a/test/Migrator/tuple-arguments.swift b/test/Migrator/tuple-arguments.swift
index 040d94f..a3ae3cc 100644
--- a/test/Migrator/tuple-arguments.swift
+++ b/test/Migrator/tuple-arguments.swift
@@ -29,6 +29,15 @@
test6({ (x:Int, y:Int) in })
test6({ (_, _) ->() in })
+func test8(_: ((Int, Int)) -> Int) {}
+test8 { (_, _) -> Int in 2 }
+test8 { (x, y) in x }
+
+func isEven(_ x: Int) -> Bool { return x % 2 == 0 }
+let items = Array(zip(0..<10, 0..<10))
+_ = items.filter { (_, x) in isEven(x) }
+_ = items.filter { _ in true }
+
func toString(indexes: Int?...) -> String {
let _ = indexes.enumerated().flatMap({ (i: Int, index: Int?) -> String? in
let _: Int = i
diff --git a/test/Migrator/tuple-arguments.swift.expected b/test/Migrator/tuple-arguments.swift.expected
index 40868d1..5b3316a 100644
--- a/test/Migrator/tuple-arguments.swift.expected
+++ b/test/Migrator/tuple-arguments.swift.expected
@@ -26,11 +26,20 @@
test7({ let (x,y,z) = $0; })
test6({ let (x, y) = $0; })
test6({ let (_, _) = $0; })
-test6({ (__val:(Int, Int)) in let (x,y) = __val; })
-test6({ (__val:(Int, Int)) ->() in let (_,_) = __val; })
+test6({ (__val:(Int, Int)) in let (x,y) = __val; })
+test6({ (__val:(Int, Int)) ->() in let (_,_) = __val; })
+
+func test8(_: ((Int, Int)) -> Int) {}
+test8 { (__val:(Int, Int)) -> Int in let (_,_) = __val; return 2 }
+test8 { let (x, y) = $0; return x }
+
+func isEven(_ x: Int) -> Bool { return x % 2 == 0 }
+let items = Array(zip(0..<10, 0..<10))
+_ = items.filter { let (_, x) = $0; return isEven(x) }
+_ = items.filter { _ in true }
func toString(indexes: Int?...) -> String {
- let _ = indexes.enumerated().flatMap({ (__val:(Int, Int?)) -> String? in let (i,index) = __val;
+ let _ = indexes.enumerated().flatMap({ (__val:(Int, Int?)) -> String? in let (i,index) = __val;
let _: Int = i
if index != nil {}
return ""