mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/main' into rebranch
This commit is contained in:
@@ -149,6 +149,9 @@ namespace swift {
|
||||
/// Should potential unavailability on enum cases be downgraded to a warning?
|
||||
bool WarnOnPotentiallyUnavailableEnumCase = false;
|
||||
|
||||
/// Should the editor placeholder error be downgraded to a warning?
|
||||
bool WarnOnEditorPlaceholder = false;
|
||||
|
||||
/// Maximum number of typo corrections we are allowed to perform.
|
||||
/// This is disabled by default until we can get typo-correction working within acceptable performance bounds.
|
||||
unsigned TypoCorrectionLimit = 0;
|
||||
|
||||
@@ -462,6 +462,10 @@ def warn_on_potentially_unavailable_enum_case : Flag<["-"],
|
||||
"warn-on-potentially-unavailable-enum-case">,
|
||||
HelpText<"Downgrade potential unavailability of enum case to a warning">;
|
||||
|
||||
def warn_on_editor_placeholder : Flag<["-"],
|
||||
"warn-on-editor-placeholder">,
|
||||
HelpText<"Downgrade the editor placeholder error to a warning">;
|
||||
|
||||
def report_errors_to_debugger : Flag<["-"], "report-errors-to-debugger">,
|
||||
HelpText<"Deprecated, will be removed in future versions.">;
|
||||
|
||||
|
||||
@@ -467,6 +467,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
|
||||
Opts.WarnOnPotentiallyUnavailableEnumCase |=
|
||||
Args.hasArg(OPT_warn_on_potentially_unavailable_enum_case);
|
||||
Opts.WarnOnEditorPlaceholder |= Args.hasArg(OPT_warn_on_editor_placeholder);
|
||||
|
||||
if (auto A = Args.getLastArg(OPT_enable_access_control,
|
||||
OPT_disable_access_control)) {
|
||||
Opts.EnableAccessControl
|
||||
|
||||
@@ -2145,9 +2145,10 @@ void Lexer::tryLexEditorPlaceholder() {
|
||||
if (Ptr[0] == '<' && Ptr[1] == '#')
|
||||
break;
|
||||
if (Ptr[0] == '#' && Ptr[1] == '>') {
|
||||
// Found it. Flag it as error (or warning, if in playground mode) for the
|
||||
// rest of the compiler pipeline and lex it as an identifier.
|
||||
if (LangOpts.Playground) {
|
||||
// Found it. Flag it as error (or warning, if in playground mode or we've
|
||||
// been asked to warn) for the rest of the compiler pipeline and lex it
|
||||
// as an identifier.
|
||||
if (LangOpts.Playground || LangOpts.WarnOnEditorPlaceholder) {
|
||||
diagnose(TokStart, diag::lex_editor_placeholder_in_playground);
|
||||
} else {
|
||||
diagnose(TokStart, diag::lex_editor_placeholder);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library %import-libdispatch) | %FileCheck %s
|
||||
|
||||
// REQUIRES: rdar82092187
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: concurrency
|
||||
// REQUIRES: libdispatch
|
||||
|
||||
@@ -14,9 +14,9 @@ typealias NestedAliasCallback = SomeCallback
|
||||
// 1. Check various functions for having/not having async alternatives
|
||||
|
||||
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+4):1 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
|
||||
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+3):6 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
|
||||
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):12 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
|
||||
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):20 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
|
||||
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+3):6 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
|
||||
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):12 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
|
||||
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):20 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
|
||||
func simple(/*cs*/ completion: @escaping (String) -> Void /*ce*/) { }
|
||||
// ASYNC-SIMPLE: basic.swift [[# @LINE-1]]:1 -> [[# @LINE-1]]:1
|
||||
// ASYNC-SIMPLE-NEXT: @available(*, renamed: "simple()")
|
||||
@@ -113,7 +113,7 @@ func errorOnly(completion: @escaping (Error?) -> Void) { }
|
||||
// ASYNC-ERRORONLY-NEXT: }
|
||||
// ASYNC-ERRORONLY: func errorOnly() async throws { }
|
||||
|
||||
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ASYNC-ERRORNONOPTIONALRESULT %s
|
||||
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ASYNC-ERRORNONOPTIONALRESULT %s
|
||||
func errorNonOptionalResult(completion: @escaping (String, Error?) -> Void) { }
|
||||
// ASYNC-ERRORNONOPTIONALRESULT: {
|
||||
// ASYNC-ERRORNONOPTIONALRESULT-NEXT: Task {
|
||||
@@ -253,7 +253,7 @@ func mixed(_ completion: @escaping (String?, Int) -> Void) { }
|
||||
// MIXED-NEXT: }
|
||||
// MIXED: func mixed() async -> (String?, Int) { }
|
||||
|
||||
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MIXED-OPTIONAL-ERROR %s
|
||||
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MIXED-OPTIONAL-ERROR %s
|
||||
func mixedOptionalError(_ completion: @escaping (String?, Int, Error?) -> Void) { }
|
||||
// MIXED-OPTIONAL-ERROR: {
|
||||
// MIXED-OPTIONAL-ERROR-NEXT: Task {
|
||||
@@ -377,7 +377,7 @@ protocol MyProtocol {
|
||||
}
|
||||
|
||||
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NON-COMPLETION %s
|
||||
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NON-COMPLETION %s
|
||||
func nonCompletion(a: Int) { }
|
||||
// NON-COMPLETION: func nonCompletion(a: Int) async { }
|
||||
|
||||
@@ -387,27 +387,27 @@ func nonEscapingCompletion(completion: (Int) -> Void) { }
|
||||
// NON-ESCAPING-COMPLETION: func nonEscapingCompletion(completion: (Int) -> Void) async { }
|
||||
|
||||
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MULTIPLE-RESULTS %s
|
||||
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MULTIPLE-RESULTS %s
|
||||
func multipleResults(completion: @escaping (Result<String, Error>, Result<String, Error>) -> Void) { }
|
||||
// MULTIPLE-RESULTS: func multipleResults(completion: @escaping (Result<String, Error>, Result<String, Error>) -> Void) async { }
|
||||
|
||||
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NON-VOID %s
|
||||
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NON-VOID %s
|
||||
func nonVoid(completion: @escaping (String) -> Void) -> Int { return 0 }
|
||||
// NON-VOID: func nonVoid(completion: @escaping (String) -> Void) async -> Int { return 0 }
|
||||
|
||||
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=COMPLETION-NON-VOID %s
|
||||
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=COMPLETION-NON-VOID %s
|
||||
func completionNonVoid(completion: @escaping (String) -> Int) -> Void { }
|
||||
// COMPLETION-NON-VOID: func completionNonVoid(completion: @escaping (String) -> Int) async -> Void { }
|
||||
|
||||
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ALREADY-THROWS %s
|
||||
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ALREADY-THROWS %s
|
||||
func alreadyThrows(completion: @escaping (String) -> Void) throws { }
|
||||
// ALREADY-THROWS: func alreadyThrows(completion: @escaping (String) -> Void) async throws { }
|
||||
|
||||
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=AUTO-CLOSURE %s
|
||||
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=AUTO-CLOSURE %s
|
||||
func noParamAutoclosure(completion: @escaping @autoclosure () -> Void) { }
|
||||
// AUTO-CLOSURE: func noParamAutoclosure(completion: @escaping @autoclosure () -> Void) async { }
|
||||
|
||||
@@ -640,13 +640,17 @@ func testSkipAssign() {
|
||||
// SKIP-ASSIGN-FUNC-NEXT: print("assigned"){{$}}
|
||||
// SKIP-ASSIGN-FUNC-NEXT: }{{$}}
|
||||
|
||||
// Same as noParamAutoclosure defined above, but used just for the test below.
|
||||
// This avoids a compiler error when converting noParamAutoclosure to async.
|
||||
func noParamAutoclosure2(completion: @escaping @autoclosure () -> Void) {}
|
||||
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefixes=SKIP-AUTOCLOSURE-FUNC %s
|
||||
func testSkipAutoclosure() {
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3
|
||||
noParamAutoclosure(completion: print("autoclosure"))
|
||||
noParamAutoclosure2(completion: print("autoclosure"))
|
||||
}
|
||||
// SKIP-AUTOCLOSURE-FUNC: {{^}}func testSkipAutoclosure() async {
|
||||
// SKIP-AUTOCLOSURE-FUNC: noParamAutoclosure(completion: print("autoclosure")){{$}}
|
||||
// SKIP-AUTOCLOSURE-FUNC: noParamAutoclosure2(completion: print("autoclosure")){{$}}
|
||||
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=EMPTY-CAPTURE %s
|
||||
func testEmptyCapture() {
|
||||
|
||||
@@ -7,13 +7,19 @@
|
||||
import Foundation
|
||||
import ConvertBoolObjC
|
||||
|
||||
func boolWithErr() async throws -> Bool { true }
|
||||
func boolWithErr(completion: @escaping (Bool, Error?) -> Void) {}
|
||||
|
||||
func multipleBoolWithErr() async throws -> (String, Bool, Bool) { ("", true, true) }
|
||||
func multipleBoolWithErr(completion: @escaping (String?, Bool, Bool, Error?) -> Void) {}
|
||||
|
||||
func optionalBoolWithErr() async throws -> (String, Bool, Bool) { ("", true, true) }
|
||||
func optionalBoolWithErr(completion: @escaping (String?, Bool?, Bool, Error?) -> Void) {}
|
||||
|
||||
func testConvertBool() async throws {
|
||||
// All 7 of the below should generate the same refactoring.
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
boolWithErr { b, err in
|
||||
if !b {
|
||||
fatalError("oh no \(err!)")
|
||||
@@ -21,7 +27,7 @@ boolWithErr { b, err in
|
||||
print("not err")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
boolWithErr { b, err in
|
||||
if b {
|
||||
fatalError("oh no \(err!)")
|
||||
@@ -29,7 +35,7 @@ boolWithErr { b, err in
|
||||
print("not err")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
boolWithErr { b, err in
|
||||
if !b && err != nil {
|
||||
fatalError("oh no \(err!)")
|
||||
@@ -37,7 +43,7 @@ boolWithErr { b, err in
|
||||
print("not err")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
boolWithErr { b, err in
|
||||
if b && err != nil {
|
||||
fatalError("oh no \(err!)")
|
||||
@@ -45,7 +51,7 @@ boolWithErr { b, err in
|
||||
print("not err")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
boolWithErr { b, err in
|
||||
if err != nil && b == false {
|
||||
fatalError("oh no \(err!)")
|
||||
@@ -53,7 +59,7 @@ boolWithErr { b, err in
|
||||
print("not err")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
boolWithErr { b, err in
|
||||
if b == true && err == nil {
|
||||
} else {
|
||||
@@ -62,7 +68,7 @@ boolWithErr { b, err in
|
||||
print("not err")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR %s
|
||||
boolWithErr { b, err in
|
||||
if !b && err == nil {
|
||||
} else {
|
||||
@@ -80,7 +86,7 @@ boolWithErr { b, err in
|
||||
|
||||
// These 3 should both generate the same refactoring.
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR2 %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR2 %s
|
||||
boolWithErr { success, err in
|
||||
if success == true && err == nil {
|
||||
print("hi")
|
||||
@@ -90,7 +96,7 @@ boolWithErr { success, err in
|
||||
print("not err")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR2 %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR2 %s
|
||||
boolWithErr { success, err in
|
||||
if success && err == nil {
|
||||
print("hi")
|
||||
@@ -100,7 +106,7 @@ boolWithErr { success, err in
|
||||
print("not err")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR2 %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR2 %s
|
||||
boolWithErr { success, err in
|
||||
if err == nil {
|
||||
print("hi")
|
||||
@@ -118,7 +124,7 @@ boolWithErr { success, err in
|
||||
// BOOL-WITH-ERR2-NEXT: fatalError("oh no \(err)")
|
||||
// BOOL-WITH-ERR2-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR3 %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR3 %s
|
||||
boolWithErr { failure, err in
|
||||
if failure {
|
||||
print("a \(err!)")
|
||||
@@ -141,7 +147,8 @@ boolWithErr { failure, err in
|
||||
// BOOL-WITH-ERR3-NEXT: }
|
||||
|
||||
// Don't handle the below example as the force unwrap of err takes place under a different condition.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-DONT-HANDLE %s
|
||||
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-DONT-HANDLE %s
|
||||
boolWithErr { success, err in
|
||||
if !success {
|
||||
if err != nil {
|
||||
@@ -165,7 +172,8 @@ boolWithErr { success, err in
|
||||
// BOOL-DONT-HANDLE-NEXT: }
|
||||
// BOOL-DONT-HANDLE-NEXT: print("not err")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-DONT-HANDLE2 %s
|
||||
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-DONT-HANDLE2 %s
|
||||
boolWithErr { success, err in
|
||||
if !success {
|
||||
func doThings() {
|
||||
@@ -218,7 +226,7 @@ boolWithErr { success, err in
|
||||
// BOOL-DONT-HANDLE2-NEXT: }
|
||||
// BOOL-DONT-HANDLE2-NEXT: print("not err")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-DONT-HANDLE3 %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-DONT-HANDLE3 %s
|
||||
boolWithErr { success, err in
|
||||
if !success {
|
||||
fatalError("oh no maybe \(String(describing: err))")
|
||||
@@ -234,7 +242,8 @@ boolWithErr { success, err in
|
||||
// BOOL-DONT-HANDLE3-NEXT: }
|
||||
// BOOL-DONT-HANDLE3-NEXT: print("not err")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-DONT-HANDLE4 %s
|
||||
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-DONT-HANDLE4 %s
|
||||
boolWithErr { failure, err in
|
||||
if failure {
|
||||
print("a")
|
||||
@@ -257,7 +266,8 @@ boolWithErr { failure, err in
|
||||
// BOOL-DONT-HANDLE4-NEXT: print("c")
|
||||
// BOOL-DONT-HANDLE4-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR-SILLY %s
|
||||
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR-SILLY %s
|
||||
boolWithErr { success, err in
|
||||
if success == false && err == nil {
|
||||
print("ummm wat \(err!)")
|
||||
@@ -273,7 +283,8 @@ boolWithErr { success, err in
|
||||
// BOOL-WITH-ERR-SILLY-NEXT: }
|
||||
// BOOL-WITH-ERR-SILLY-NEXT: print("not err")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR-SILLY2 %s
|
||||
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-WITH-ERR-SILLY2 %s
|
||||
boolWithErr { success, err in
|
||||
if success {
|
||||
print("ummm wat \(err!)")
|
||||
@@ -291,7 +302,7 @@ boolWithErr { success, err in
|
||||
// BOOL-WITH-ERR-SILLY2-NEXT: print("ummm wat \(<#err#>!)")
|
||||
// BOOL-WITH-ERR-SILLY2-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=MULTI-BOOL-WITH-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=MULTI-BOOL-WITH-ERR %s
|
||||
multipleBoolWithErr { str, b1, b2, err in
|
||||
if !b1 && !b2 {
|
||||
print("a \(err!)")
|
||||
@@ -327,7 +338,8 @@ multipleBoolWithErr { str, b1, b2, err in
|
||||
// MULTI-BOOL-WITH-ERR-NEXT: print("d \(err)")
|
||||
// MULTI-BOOL-WITH-ERR-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OPT-BOOL-WITH-ERR %s
|
||||
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OPT-BOOL-WITH-ERR %s
|
||||
optionalBoolWithErr { str, optBool, b, err in
|
||||
if optBool != nil {
|
||||
print("a \(err!)")
|
||||
@@ -372,7 +384,8 @@ optionalBoolWithErr { str, optBool, b, err in
|
||||
// OPT-BOOL-WITH-ERR-NEXT: print("g \(err)")
|
||||
// OPT-BOOL-WITH-ERR-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OBJC-BOOL-WITH-ERR %s
|
||||
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OBJC-BOOL-WITH-ERR %s
|
||||
ClassWithHandlerMethods.firstBoolFlagSuccess("") { str, success, unrelated, err in
|
||||
if !unrelated {
|
||||
print(err!)
|
||||
@@ -403,7 +416,8 @@ ClassWithHandlerMethods.firstBoolFlagSuccess("") { str, success, unrelated, err
|
||||
// OBJC-BOOL-WITH-ERR-NEXT: print(err)
|
||||
// OBJC-BOOL-WITH-ERR-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OBJC-BOOL-WITH-ERR2 %s
|
||||
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OBJC-BOOL-WITH-ERR2 %s
|
||||
ClassWithHandlerMethods.secondBoolFlagFailure("") { str, unrelated, failure, err in
|
||||
if unrelated {
|
||||
print(err!)
|
||||
@@ -447,3 +461,4 @@ ClassWithHandlerMethods.secondBoolFlagFailure("") { str, unrelated, failure, err
|
||||
// OBJC-BOOL-WITH-ERR2-NEXT: print("neat")
|
||||
// OBJC-BOOL-WITH-ERR2-NEXT: print("neato")
|
||||
// OBJC-BOOL-WITH-ERR2-NEXT: }
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ func voidResultCompletion(completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
// VOID-RESULT-HANDLER-NEXT: }
|
||||
|
||||
// rdar://77789360 Make sure we don't print a double return statement.
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=RETURN-HANDLING %s
|
||||
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=RETURN-HANDLING %s
|
||||
func testReturnHandling(_ completion: @escaping (String?, Error?) -> Void) {
|
||||
return completion("", nil)
|
||||
}
|
||||
@@ -279,6 +279,8 @@ func testReturnHandling(_ completion: @escaping (String?, Error?) -> Void) {
|
||||
|
||||
// rdar://77789360 Make sure we don't print a double return statement and don't
|
||||
// completely drop completion(a).
|
||||
// Note we cannot use refactor-check-compiles here, as the placeholders mean we
|
||||
// don't form valid AST.
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=RETURN-HANDLING2 %s
|
||||
func testReturnHandling2(completion: @escaping (String) -> ()) {
|
||||
simpleErr(arg: "") { x, err in
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// REQUIRES: concurrency
|
||||
|
||||
func manyWithError() async throws -> (String, Int) { ("", 0) }
|
||||
func manyWithError(_ completion: @escaping (String?, Int?, Error?) -> Void) { }
|
||||
|
||||
func mixed() async -> (String, Int) { ("", 0) }
|
||||
func mixed(_ completion: @escaping (String?, Int) -> Void) { }
|
||||
|
||||
func mixedError() async throws -> (String, Int) { ("", 0) }
|
||||
func mixedError(_ completion: @escaping (String?, Int, Error?) -> Void) { }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYBOUND %s
|
||||
func testParamsMulti() async throws {
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYBOUND %s
|
||||
manyWithError { res1, res2, err in
|
||||
print("before")
|
||||
if let bad = err {
|
||||
@@ -34,7 +42,7 @@ manyWithError { res1, res2, err in
|
||||
// alternative that still returns optional success values, and allow success
|
||||
// classification in that case. Otherwise, we'd probably be better off leaving
|
||||
// the condition unhandled, as it's not clear what the user is doing.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND-ERR %s
|
||||
manyWithError { res1, res2, err in
|
||||
print("before")
|
||||
if let str = res1 {
|
||||
@@ -56,7 +64,7 @@ manyWithError { res1, res2, err in
|
||||
// MANYUNBOUND-ERR-NEXT: print("got error \(err)")
|
||||
// MANYUNBOUND-ERR-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYBOUND %s
|
||||
manyWithError { res1, res2, err in
|
||||
print("before")
|
||||
if let bad = err {
|
||||
@@ -72,7 +80,7 @@ manyWithError { res1, res2, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MIXED-COND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MIXED-COND %s
|
||||
manyWithError { res1, res2, err in
|
||||
print("before")
|
||||
if res1 != nil && res2 == nil {
|
||||
@@ -88,7 +96,7 @@ manyWithError { res1, res2, err in
|
||||
// MIXED-COND-NEXT: }
|
||||
// MIXED-COND-NEXT: print("after")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MIXED-CONDELSE %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MIXED-CONDELSE %s
|
||||
manyWithError { res1, res2, err in
|
||||
print("before")
|
||||
if res1 != nil && res2 == nil {
|
||||
@@ -115,7 +123,7 @@ manyWithError { res1, res2, err in
|
||||
// MIXED-CONDELSE-NEXT: }
|
||||
// MIXED-CONDELSE-NEXT: print("after")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND-ERR %s
|
||||
manyWithError { res1, res2, err in
|
||||
print("before")
|
||||
guard let str = res1, let i = res2 else {
|
||||
@@ -127,7 +135,7 @@ manyWithError { res1, res2, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND %s
|
||||
manyWithError { res1, res2, err in
|
||||
print("before")
|
||||
guard res1 != nil && res2 != nil && err == nil else {
|
||||
@@ -148,7 +156,7 @@ manyWithError { res1, res2, err in
|
||||
// MANYUNBOUND-NEXT: print("got error \(err)")
|
||||
// MANYUNBOUND-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND %s
|
||||
manyWithError { res1, res2, err in
|
||||
print("before")
|
||||
guard res1 != nil else {
|
||||
@@ -160,7 +168,7 @@ manyWithError { res1, res2, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYUNBOUND %s
|
||||
manyWithError { res1, res2, err in
|
||||
print("before")
|
||||
guard err == nil else {
|
||||
@@ -172,7 +180,9 @@ manyWithError { res1, res2, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MIXED %s
|
||||
// Cannot use refactor-check-compiles, as cannot use non-optional 'str' in
|
||||
// optional binding.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MIXED %s
|
||||
mixed { str, num in
|
||||
print("before")
|
||||
if let res = str {
|
||||
@@ -191,7 +201,7 @@ mixed { str, num in
|
||||
// MIXED-NEXT: print("after")
|
||||
// MIXED-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MIXED-ERROR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MIXED-ERROR %s
|
||||
mixedError { str, num, err in
|
||||
print("before")
|
||||
if let res = str {
|
||||
@@ -213,3 +223,4 @@ mixedError { str, num, err in
|
||||
// MIXED-ERROR-NEXT: print("got \(err)")
|
||||
// MIXED-ERROR-NEXT: }
|
||||
// MIXED-ERROR-NOT: }
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// REQUIRES: concurrency
|
||||
|
||||
func withError() async throws -> String { "" }
|
||||
func withError(_ completion: @escaping (String?, Error?) -> Void) { }
|
||||
|
||||
func notOptional() async throws -> String { "" }
|
||||
func notOptional(_ completion: @escaping (String, Error?) -> Void) { }
|
||||
|
||||
func errorOnly() async throws { }
|
||||
func errorOnly(_ completion: @escaping (Error?) -> Void) { }
|
||||
|
||||
func test(_ str: String) -> Bool { return false }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNRELATED %s
|
||||
func testParamsSingle() async throws {
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNRELATED %s
|
||||
withError { res, err in
|
||||
if test("unrelated") {
|
||||
print("unrelated")
|
||||
@@ -21,7 +30,7 @@ withError { res, err in
|
||||
// UNRELATED-NEXT: print("else unrelated")
|
||||
// UNRELATED-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=BOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=BOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let bad = err {
|
||||
@@ -42,7 +51,7 @@ withError { res, err in
|
||||
// BOUND-NEXT: print("got error \(bad)")
|
||||
// BOUND-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=BOUND-COMMENT %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=BOUND-COMMENT %s
|
||||
withError { res, err in // a
|
||||
// b
|
||||
print("before")
|
||||
@@ -78,7 +87,7 @@ withError { res, err in // a
|
||||
// BOUND-COMMENT-NEXT: // l
|
||||
// BOUND-COMMENT-NEXT: print("after")
|
||||
// BOUND-COMMENT-NEXT: // m
|
||||
// BOUND-COMMENT-EMPTY:
|
||||
// BOUND-COMMENT-NEXT: {{ }}
|
||||
// BOUND-COMMENT-NEXT: } catch let bad {
|
||||
// BOUND-COMMENT-NEXT: // d
|
||||
// BOUND-COMMENT-NEXT: // e
|
||||
@@ -89,7 +98,7 @@ withError { res, err in // a
|
||||
// BOUND-COMMENT-NEXT: }
|
||||
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-ERR %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
guard let str = res else {
|
||||
@@ -108,7 +117,7 @@ withError { res, err in
|
||||
// UNBOUND-ERR-NEXT: print("got error \(err)")
|
||||
// UNBOUND-ERR-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=BOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=BOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let bad = err {
|
||||
@@ -119,7 +128,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=BOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=BOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let bad = err {
|
||||
@@ -132,7 +141,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-RES %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-RES %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let bad = err {
|
||||
@@ -151,7 +160,7 @@ withError { res, err in
|
||||
// UNBOUND-RES-NEXT: print("got error \(bad)")
|
||||
// UNBOUND-RES-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-ERR %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let str = res {
|
||||
@@ -162,7 +171,7 @@ withError { res, err in
|
||||
print("got error \(err!)")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-RES %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-RES %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let bad = err {
|
||||
@@ -173,7 +182,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-ERR %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let str = res {
|
||||
@@ -184,7 +193,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if err != nil {
|
||||
@@ -203,7 +212,7 @@ withError { res, err in
|
||||
// UNBOUND-NEXT: print("got error \(err)")
|
||||
// UNBOUND-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if res != nil {
|
||||
@@ -214,7 +223,7 @@ withError { res, err in
|
||||
print("got error \(err!)")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if err != nil {
|
||||
@@ -225,7 +234,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if res != nil {
|
||||
@@ -236,7 +245,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if err == nil {
|
||||
@@ -247,7 +256,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if res == nil {
|
||||
@@ -258,6 +267,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// Cannot use refactor-check-compiles because of the placeholder, compiler is unable to infer 'str'.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNHANDLEDNESTED %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
@@ -281,7 +291,7 @@ withError { res, err in
|
||||
// UNHANDLEDNESTED-NEXT: print("got error \(bad)")
|
||||
// UNHANDLEDNESTED-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NOERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NOERR %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let str = res {
|
||||
@@ -296,7 +306,7 @@ withError { res, err in
|
||||
// NOERR-NEXT: print("after")
|
||||
// NOERR-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NORES %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NORES %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let bad = err {
|
||||
@@ -312,7 +322,7 @@ withError { res, err in
|
||||
// NORES-NEXT: print("got error \(bad)")
|
||||
// NORES-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if ((res != (nil)) && err == nil) {
|
||||
@@ -323,7 +333,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNKNOWN-COND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNKNOWN-COND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if res != nil && test(res!) {
|
||||
@@ -339,7 +349,7 @@ withError { res, err in
|
||||
// UNKNOWN-COND-NEXT: }
|
||||
// UNKNOWN-COND-NEXT: print("after")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNKNOWN-CONDELSE %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNKNOWN-CONDELSE %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if res != nil && test(res!) {
|
||||
@@ -365,7 +375,7 @@ withError { res, err in
|
||||
// UNKNOWN-CONDELSE-NEXT: }
|
||||
// UNKNOWN-CONDELSE-NEXT: print("after")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MULTIBIND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MULTIBIND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let str = res {
|
||||
@@ -386,7 +396,7 @@ withError { res, err in
|
||||
// MULTIBIND-NEXT: print("got result \(str)")
|
||||
// MULTIBIND-NEXT: print("after")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NESTEDRET %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NESTEDRET %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
if let str = res {
|
||||
@@ -407,7 +417,7 @@ withError { res, err in
|
||||
// NESTEDRET-NEXT: print("after")
|
||||
// NESTEDRET-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-ERR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND-ERR %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
guard let str = res, err == nil else {
|
||||
@@ -418,7 +428,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
guard res != nil else {
|
||||
@@ -429,7 +439,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
guard err == nil else {
|
||||
@@ -440,7 +450,7 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNBOUND %s
|
||||
withError { res, err in
|
||||
print("before")
|
||||
guard res != nil && err == nil else {
|
||||
@@ -451,6 +461,8 @@ withError { res, err in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// Cannot use refactor-check-compiles as transform results in invalid code,
|
||||
// see comment below.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNWRAPPING %s
|
||||
withError { str, err in
|
||||
print("before")
|
||||
@@ -485,7 +497,7 @@ withError { str, err in
|
||||
// UNWRAPPING-NEXT: _ = (str.first?.isWhitespace)!
|
||||
// UNWRAPPING-NEXT: print("after")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NOT-OPTIONAL %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NOT-OPTIONAL %s
|
||||
notOptional { str, err in
|
||||
print("before")
|
||||
if let err2 = err {
|
||||
@@ -504,7 +516,7 @@ notOptional { str, err in
|
||||
// NOT-OPTIONAL-NEXT: print("got error \(err2)")
|
||||
// NOT-OPTIONAL-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ERROR-ONLY %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=ERROR-ONLY %s
|
||||
errorOnly { err in
|
||||
print("before")
|
||||
if let err2 = err {
|
||||
@@ -522,3 +534,4 @@ errorOnly { err in
|
||||
// ERROR-ONLY-NEXT: print("got error \(err2)")
|
||||
// ERROR-ONLY-NEXT: }
|
||||
// ERROR-ONLY-NOT: }
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func testPatterns() async throws {
|
||||
// FALLBACK-NEXT: guard let (str1, str2) = strs, str1 == "hi" else { fatalError() }
|
||||
// FALLBACK-NEXT: print(str1, str2, err)
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=GUARD-AND-UNHANDLED %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=GUARD-AND-UNHANDLED %s
|
||||
stringTupleParam { strs, err in
|
||||
guard let (str1, str2) = strs else { fatalError() }
|
||||
print(str1, str2)
|
||||
@@ -436,6 +436,7 @@ func testNameCollision2(_ completion: @escaping () -> Void) {
|
||||
// NAME-COLLISION2-NEXT: print("b", x, y, z)
|
||||
// NAME-COLLISION2-NEXT: }
|
||||
|
||||
// Cannot use refactor-check-compiles, as cannot pattern match with placeholders.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=TEST-UNHANDLED %s
|
||||
anyCompletion { val, err in
|
||||
if let x = val {
|
||||
@@ -552,7 +553,7 @@ anyResultCompletion { res in
|
||||
|
||||
// Make sure we handle a capture list okay.
|
||||
class C {
|
||||
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=CAPTURE %s
|
||||
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=CAPTURE %s
|
||||
func foo() {
|
||||
let _ = { [weak self] in
|
||||
print(self!)
|
||||
|
||||
@@ -1,33 +1,48 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// REQUIRES: concurrency
|
||||
|
||||
func simple(_ completion: @escaping (Result<String, Error>) -> Void) { }
|
||||
func simple() async throws -> String { "" }
|
||||
|
||||
func simpleWithArg(_ arg: Int) async throws -> String { "" }
|
||||
func simpleWithArg(_ arg: Int, _ completion: @escaping (Result<String, Error>) -> Void) { }
|
||||
|
||||
func noError() async -> String { "" }
|
||||
func noError(_ completion: @escaping (Result<String, Never>) -> Void) { }
|
||||
|
||||
func voidNoError() async {}
|
||||
func voidNoError(completion: @escaping (Result<Void, Never>) -> Void) {}
|
||||
|
||||
func voidError() async throws {}
|
||||
func voidError(completion: @escaping (Result<Void, Error>) -> Void) {}
|
||||
|
||||
func test(_ str: String) -> Bool { return false }
|
||||
|
||||
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix VOID-RESULT %s
|
||||
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix VOID-RESULT %s
|
||||
func voidResult(completion: @escaping (Result<Void, Never>) -> Void) {}
|
||||
// VOID-RESULT: func voidResult() async {}
|
||||
|
||||
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix VOID-AND-ERROR-RESULT %s
|
||||
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix VOID-AND-ERROR-RESULT %s
|
||||
func voidAndErrorResult(completion: @escaping (Result<Void, Error>) -> Void) {}
|
||||
// VOID-AND-ERROR-RESULT: func voidAndErrorResult() async throws {}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=SIMPLE %s
|
||||
func testResultConversion() async throws {
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=SIMPLE %s
|
||||
simple { res in
|
||||
print("result \(res)")
|
||||
}
|
||||
// SIMPLE: let res = try await simple()
|
||||
// SIMPLE-NEXT: print("result \(<#res#>)")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NOERROR %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NOERROR %s
|
||||
noError { res in
|
||||
print("result \(res)")
|
||||
}
|
||||
// NOERROR: let res = await noError()
|
||||
// NOERROR-NEXT: print("result \(<#res#>)")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=DOBLOCK %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=DOBLOCK %s
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -47,7 +62,7 @@ simple { res in
|
||||
// DOBLOCK-NEXT: print("error \(err)")
|
||||
// DOBLOCK-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=DOBLOCK %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=DOBLOCK %s
|
||||
simple { res in
|
||||
print("before")
|
||||
if case .success(let str) = res {
|
||||
@@ -58,7 +73,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=DOBLOCK %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=DOBLOCK %s
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -72,7 +87,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=DOBLOCK %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=DOBLOCK %s
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -86,7 +101,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=SUCCESS %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=SUCCESS %s
|
||||
simple { res in
|
||||
print("before")
|
||||
if case .success(let str) = res {
|
||||
@@ -101,7 +116,7 @@ simple { res in
|
||||
// SUCCESS-NEXT: print("after")
|
||||
// SUCCESS-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=SUCCESS %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=SUCCESS %s
|
||||
simple { res in
|
||||
print("before")
|
||||
guard case .success(let str) = res else {
|
||||
@@ -111,7 +126,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=DOBLOCKUNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=DOBLOCKUNBOUND %s
|
||||
simple { res in
|
||||
print("before")
|
||||
guard case .success(let str) = res else {
|
||||
@@ -130,7 +145,7 @@ simple { res in
|
||||
// DOBLOCKUNBOUND-NEXT: print("err")
|
||||
// DOBLOCKUNBOUND-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=SUCCESS %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=SUCCESS %s
|
||||
simple { res in
|
||||
print("before")
|
||||
if let str = try? res.get() {
|
||||
@@ -139,7 +154,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=DOBLOCKUNBOUND %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=DOBLOCKUNBOUND %s
|
||||
simple { res in
|
||||
print("before")
|
||||
guard let str = try? res.get() else {
|
||||
@@ -150,7 +165,8 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=UNKNOWN %s
|
||||
// Cannot use refactor-check-compiles, as cannot infer type of the 'get' member on the placeholder.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNKNOWN %s
|
||||
simple { res in
|
||||
print("before \(res)")
|
||||
if case .success(let str) = res {
|
||||
@@ -165,7 +181,8 @@ simple { res in
|
||||
// UNKNOWN-NEXT: print("after")
|
||||
// UNKNOWN-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=UNKNOWNUNBOUND %s
|
||||
// Cannot use refactor-check-compiles, as cannot infer type of the 'get' member on the placeholder.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNKNOWNUNBOUND %s
|
||||
simple { res in
|
||||
print("before \(res)")
|
||||
if case .success = res {
|
||||
@@ -180,7 +197,7 @@ simple { res in
|
||||
// UNKNOWNUNBOUND-NEXT: print("after")
|
||||
// UNKNOWN-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MULTIPLE-BINDS %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MULTIPLE-BINDS %s
|
||||
simple { res in
|
||||
print("before")
|
||||
if case .success(let str) = res {
|
||||
@@ -199,7 +216,7 @@ simple { res in
|
||||
// MULTIPLE-BINDS-NEXT: print("after")
|
||||
// MULTIPLE-BINDS-NOT: }
|
||||
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -213,7 +230,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -225,7 +242,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -235,7 +252,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -245,7 +262,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -257,7 +274,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
|
||||
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -271,7 +288,7 @@ simple { res in
|
||||
print("after")
|
||||
}
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NESTEDRET %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NESTEDRET %s
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -295,7 +312,7 @@ simple { res in
|
||||
// NESTEDRET-NEXT: print("after")
|
||||
// NESTEDRET-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NESTEDBREAK %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NESTEDBREAK %s
|
||||
simple { res in
|
||||
print("before")
|
||||
switch res {
|
||||
@@ -319,7 +336,7 @@ simple { res in
|
||||
// NESTEDBREAK-NEXT: print("after")
|
||||
// NESTEDBREAK-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NESTEDBREAK-COMMENT %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=NESTEDBREAK-COMMENT %s
|
||||
simple { res in // a
|
||||
// b
|
||||
print("before")
|
||||
@@ -364,10 +381,10 @@ simple { res in // a
|
||||
// NESTEDBREAK-COMMENT-NEXT: // l
|
||||
// NESTEDBREAK-COMMENT-NEXT: print("after")
|
||||
// NESTEDBREAK-COMMENT-NEXT: // m
|
||||
// NESTEDBREAK-COMMENT-EMPTY:
|
||||
// NESTEDBREAK-COMMENT-NEXT: {{ }}
|
||||
// NESTEDBREAK-COMMENT-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ERROR-BLOCK-COMMENT %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=ERROR-BLOCK-COMMENT %s
|
||||
simple { res in
|
||||
// a
|
||||
print("before")
|
||||
@@ -399,7 +416,7 @@ simple { res in
|
||||
// ERROR-BLOCK-COMMENT-NEXT: // h
|
||||
// ERROR-BLOCK-COMMENT-NEXT: print("after")
|
||||
// ERROR-BLOCK-COMMENT-NEXT: // i
|
||||
// ERROR-BLOCK-COMMENT-EMPTY:
|
||||
// ERROR-BLOCK-COMMENT-NEXT: {{ }}
|
||||
// ERROR-BLOCK-COMMENT-NEXT: } catch {
|
||||
// ERROR-BLOCK-COMMENT-NEXT: // e
|
||||
// ERROR-BLOCK-COMMENT-NEXT: print("fail")
|
||||
@@ -409,22 +426,22 @@ simple { res in
|
||||
// ERROR-BLOCK-COMMENT-NEXT: }
|
||||
// ERROR-BLOCK-COMMENT-NOT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=VOID-RESULT-CALL %s
|
||||
voidResult { res in
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=VOID-RESULT-CALL %s
|
||||
voidNoError { res in
|
||||
print(res)
|
||||
}
|
||||
// VOID-RESULT-CALL: {{^}}await voidResult()
|
||||
// VOID-RESULT-CALL: {{^}}await voidNoError()
|
||||
// VOID-RESULT-CALL: {{^}}print(<#res#>)
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=VOID-AND-ERROR-RESULT-CALL %s
|
||||
voidAndErrorResult { res in
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=VOID-AND-ERROR-RESULT-CALL %s
|
||||
voidError { res in
|
||||
print(res)
|
||||
}
|
||||
// VOID-AND-ERROR-RESULT-CALL: {{^}}try await voidAndErrorResult()
|
||||
// VOID-AND-ERROR-RESULT-CALL: {{^}}try await voidError()
|
||||
// VOID-AND-ERROR-RESULT-CALL: {{^}}print(<#res#>)
|
||||
|
||||
// Make sure we ignore an unrelated switch.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=IGNORE-UNRELATED %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=IGNORE-UNRELATED %s
|
||||
simple { res in
|
||||
print("before")
|
||||
switch Bool.random() {
|
||||
@@ -445,7 +462,7 @@ simple { res in
|
||||
// IGNORE-UNRELATED-NEXT: }
|
||||
// IGNORE-UNRELATED-NEXT: print("after")
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=BREAK-RET-PLACEHOLDER %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=BREAK-RET-PLACEHOLDER %s
|
||||
simpleWithArg({ return 0 }()) { res in
|
||||
switch res {
|
||||
case .success:
|
||||
@@ -511,3 +528,4 @@ simpleWithArg({ return 0 }()) { res in
|
||||
// BREAK-RET-PLACEHOLDER-NEXT: {{^}} break x{{$}}
|
||||
// BREAK-RET-PLACEHOLDER-NEXT: }
|
||||
// BREAK-RET-PLACEHOLDER-NEXT: if .random() { <#return#> }
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func testPathClassification() async throws {
|
||||
// ELSE-IF-CLASSIFICATION-NEXT: print("d")
|
||||
// ELSE-IF-CLASSIFICATION-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=ELSE-IF-CLASSIFICATION2 %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=ELSE-IF-CLASSIFICATION2 %s
|
||||
simpleWithError { str, err in
|
||||
if err == nil {
|
||||
print("a")
|
||||
@@ -172,6 +172,8 @@ func testPathClassification() async throws {
|
||||
// ELSE-IF-CLASSIFICATION5-NEXT: }
|
||||
// ELSE-IF-CLASSIFICATION5-NEXT: }
|
||||
|
||||
// Cannot use refactor-check-compiles, as 'err' cannot have its type inferred
|
||||
// from placeholder.
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=IF-LET-RETURN-CLASSIFICATION %s
|
||||
simpleWithError { str, err in
|
||||
if let str = str {
|
||||
@@ -196,7 +198,7 @@ func testPathClassification() async throws {
|
||||
// IF-LET-RETURN-CLASSIFICATION-NEXT: }
|
||||
// IF-LET-RETURN-CLASSIFICATION-NEXT: }
|
||||
|
||||
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=GUARD-CLASSIFICATION %s
|
||||
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=GUARD-CLASSIFICATION %s
|
||||
simpleWithError { str, err in
|
||||
guard let str = str else {
|
||||
print("a")
|
||||
|
||||
@@ -23,7 +23,8 @@ def parse_args():
|
||||
A drop-in replacement for a 'swift-refactor -dump-text' call that
|
||||
1. Checks that the file still compiles after the refactoring by doing
|
||||
'swift-refactor -dump-rewritten' and feeding the result to
|
||||
'swift-frontend -typecheck'
|
||||
'swift-frontend -typecheck -disable-availability-checking
|
||||
-warn-on-editor-placeholder'
|
||||
2. Outputting the result of the 'swift-refactor -dump-text' call
|
||||
|
||||
All arguments other than the following will be forwarded to
|
||||
@@ -32,6 +33,9 @@ def parse_args():
|
||||
- swift-refactor
|
||||
- temp-dir
|
||||
- enable-experimental-concurrency (sent to both)
|
||||
- I (sent to both)
|
||||
- sdk (sent to both)
|
||||
- target (sent to both)
|
||||
""")
|
||||
|
||||
parser.add_argument(
|
||||
@@ -70,6 +74,19 @@ def parse_args():
|
||||
swift-frontend
|
||||
'''
|
||||
)
|
||||
parser.add_argument(
|
||||
'-I',
|
||||
action='append',
|
||||
help='Add a directory to the import search path'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-sdk',
|
||||
help='Path to the SDK to build against'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-target',
|
||||
help='The target triple to build for'
|
||||
)
|
||||
|
||||
return parser.parse_known_args()
|
||||
|
||||
@@ -80,10 +97,16 @@ def main():
|
||||
args.pos.replace(':', '.')
|
||||
temp_file_path = os.path.join(args.temp_dir, temp_file_name)
|
||||
|
||||
extra_frontend_args = []
|
||||
extra_both_args = []
|
||||
if args.enable_experimental_concurrency:
|
||||
extra_refactor_args.append('-enable-experimental-concurrency')
|
||||
extra_frontend_args.append('-enable-experimental-concurrency')
|
||||
extra_both_args.append('-enable-experimental-concurrency')
|
||||
if args.I:
|
||||
for path in args.I:
|
||||
extra_both_args += ['-I', path]
|
||||
if args.sdk:
|
||||
extra_both_args += ['-sdk', args.sdk]
|
||||
if args.target:
|
||||
extra_both_args += ['-target', args.target]
|
||||
|
||||
dump_text_output = run_cmd([
|
||||
args.swift_refactor,
|
||||
@@ -91,15 +114,16 @@ def main():
|
||||
'-source-filename', args.source_filename,
|
||||
'-rewritten-output-file', temp_file_path,
|
||||
'-pos', args.pos
|
||||
] + extra_refactor_args, desc='producing edit').decode("utf-8")
|
||||
] + extra_refactor_args + extra_both_args, desc='producing edit').decode("utf-8")
|
||||
sys.stdout.write(dump_text_output)
|
||||
|
||||
run_cmd([
|
||||
args.swift_frontend,
|
||||
'-typecheck',
|
||||
temp_file_path,
|
||||
'-disable-availability-checking'
|
||||
] + extra_frontend_args, desc='checking that rewritten file compiles')
|
||||
'-disable-availability-checking',
|
||||
'-warn-on-editor-placeholder'
|
||||
] + extra_both_args, desc='checking that rewritten file compiles')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user