diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index ab8584542b2..712da2ff2bc 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -273,8 +273,8 @@ ERROR(cannot_infer_closure_parameter_type,none, ERROR(cannot_infer_closure_type,none, "unable to infer closure type in the current context", ()) ERROR(cannot_infer_closure_result_type,none, - "unable to infer%select{ complex|}0 closure return type; " - "add explicit type to disambiguate", (bool)) + "cannot infer return type for closure with multiple statements; " + "add explicit type to disambiguate", ()) FIXIT(insert_closure_return_type_placeholder, "%select{| () }0-> <#Result#> %select{|in }0", (bool)) diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index ccc9f095404..405caa09cbe 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -6845,8 +6845,7 @@ bool UnableToInferClosureParameterType::diagnoseAsError() { bool UnableToInferClosureReturnType::diagnoseAsError() { auto *closure = castToExpr(getRawAnchor()); - auto diagnostic = emitDiagnostic(diag::cannot_infer_closure_result_type, - closure->hasSingleExpressionBody()); + auto diagnostic = emitDiagnostic(diag::cannot_infer_closure_result_type); // If there is a location for an 'in' token, then the argument list was // specified somehow but no return type was. Insert a "-> ReturnType " diff --git a/test/Constraints/closures.swift b/test/Constraints/closures.swift index a4d0a00afcd..1c164b8dc97 100644 --- a/test/Constraints/closures.swift +++ b/test/Constraints/closures.swift @@ -252,7 +252,7 @@ struct CC {} func callCC(_ f: (CC) -> U) -> () {} func typeCheckMultiStmtClosureCrash() { - callCC { // expected-error {{unable to infer complex closure return type; add explicit type to disambiguate}} {{none}} + callCC { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{none}} _ = $0 return 1 } @@ -313,7 +313,7 @@ struct Thing { init?() {} } // This throws a compiler error -let things = Thing().map { thing in // expected-error {{unable to infer complex closure return type; add explicit type to disambiguate}} {{34-34=-> <#Result#> }} +let things = Thing().map { thing in // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{34-34=-> <#Result#> }} // Commenting out this makes it compile _ = thing return thing @@ -322,7 +322,7 @@ let things = Thing().map { thing in // expected-error {{unable to infer complex // QoI: [Closure return type inference] Swift cannot find members for the result of inlined lambdas with branches func r21675896(file : String) { - let x: String = { // expected-error {{unable to infer complex closure return type; add explicit type to disambiguate}} {{20-20= () -> <#Result#> in }} + let x: String = { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{20-20= () -> <#Result#> in }} if true { return "foo" } @@ -360,7 +360,7 @@ func someGeneric19997471(_ x: T) { // Swift fails to compile: [0].map() { _ in let r = (1,2).0; return r } -[0].map { // expected-error {{unable to infer complex closure return type; add explicit type to disambiguate}} {{5-5=-> <#Result#> }} +[0].map { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{5-5=-> <#Result#> }} _ in let r = (1,2).0 return r @@ -408,7 +408,7 @@ func r20789423() { print(p.f(p)()) // expected-error {{cannot convert value of type 'C' to expected argument type 'Int'}} // expected-error@-1:11 {{cannot call value of non-function type '()'}} - let _f = { (v: Int) in // expected-error {{unable to infer complex closure return type; add explicit type to disambiguate}} {{23-23=-> <#Result#> }} + let _f = { (v: Int) in // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{23-23=-> <#Result#> }} print("a") return "hi" } diff --git a/test/Constraints/diagnostics.swift b/test/Constraints/diagnostics.swift index 7457bdae9d2..f8fd1785fec 100644 --- a/test/Constraints/diagnostics.swift +++ b/test/Constraints/diagnostics.swift @@ -161,7 +161,7 @@ public func myMap(_ x: T?, _ f: (T) -> U) -> U? { // func rdar20142523() { - myMap(0..<10, { x in // expected-error{{unable to infer complex closure return type; add explicit type to disambiguate}} {{21-21=-> <#Result#> }} {{educational-notes=complex-closure-inference}} + myMap(0..<10, { x in // expected-error{{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{21-21=-> <#Result#> }} {{educational-notes=complex-closure-inference}} () return x }) diff --git a/test/Constraints/patterns.swift b/test/Constraints/patterns.swift index a709fb5f809..8921165e91a 100644 --- a/test/Constraints/patterns.swift +++ b/test/Constraints/patterns.swift @@ -230,14 +230,14 @@ func good(_ a: A) -> Int { } func bad(_ a: A) { - a.map { // expected-error {{unable to infer complex closure return type; add explicit type to disambiguate}} {{none}} + a.map { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{none}} let _: EE = $0 return 1 } } func ugly(_ a: A) { - a.map { // expected-error {{unable to infer complex closure return type; add explicit type to disambiguate}} {{none}} + a.map { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{none}} switch $0 { case .A: return 1 diff --git a/test/diagnostics/pretty-printed-diagnostics.swift b/test/diagnostics/pretty-printed-diagnostics.swift index 667baca9789..b110ecfa45c 100644 --- a/test/diagnostics/pretty-printed-diagnostics.swift +++ b/test/diagnostics/pretty-printed-diagnostics.swift @@ -128,7 +128,7 @@ foo(b: // CHECK: [[#LINE-1]] | // CHECK: [[#LINE]] | let x = { () -> Result in // CHECK: | +++++++++++++++++ -// CHECK: | ^ error: unable to infer complex closure return type; add explicit type to disambiguate +// CHECK: | ^ error: cannot infer return type for closure with multiple statements; add explicit type to disambiguate // CHECK: [[#LINE+1]] | let y = 1 // CHECK: SOURCE_DIR{{[/\]+}}test{{[/\]+}}diagnostics{{[/\]+}}pretty-printed-diagnostics.swift:[[#LINE:]]:8 @@ -152,7 +152,7 @@ foo(b: // CHECK: SOURCE_DIR{{[/\]+}}test{{[/\]+}}diagnostics{{[/\]+}}pretty-printed-diagnostics.swift:[[#LINE:]]:20 // CHECK: [[#LINE-1]] | // CHECK: [[#LINE]] | let 👍👍👍 = { -// CHECK: | --> error: unable to infer complex closure return type; add explicit type to disambiguate [insert ' () -> <#Result#> in '] +// CHECK: | --> error: cannot infer return type for closure with multiple statements; add explicit type to disambiguate [insert ' () -> <#Result#> in '] // CHECK: [[#LINE+1]] | let y = 1 // CHECK: SOURCE_DIR{{[/\]+}}test{{[/\]+}}diagnostics{{[/\]+}}pretty-printed-diagnostics.swift:[[#LINE:]]:5 diff --git a/test/expr/closure/closures.swift b/test/expr/closure/closures.swift index 1b501f72790..9eeeefeb442 100644 --- a/test/expr/closure/closures.swift +++ b/test/expr/closure/closures.swift @@ -403,7 +403,7 @@ Void(0) // expected-error{{argument passed to call that takes no arguments}} _ = {0} // "multi-statement closures require an explicit return type" should be an error not a note -let samples = { // expected-error {{unable to infer complex closure return type; add explicit type to disambiguate}} {{16-16= () -> <#Result#> in }} +let samples = { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{16-16= () -> <#Result#> in }} if (i > 10) { return true } else { return false } }() @@ -485,7 +485,7 @@ func lvalueCapture(c: GenericClass) { } // Don't expose @lvalue-ness in diagnostics. -let closure = { // expected-error {{unable to infer complex closure return type; add explicit type to disambiguate}} {{16-16= () -> <#Result#> in }} +let closure = { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{16-16= () -> <#Result#> in }} var helper = true return helper } diff --git a/userdocs/diagnostics/complex-closure-inference.md b/userdocs/diagnostics/complex-closure-inference.md index ad769a86c01..99f53362af1 100644 --- a/userdocs/diagnostics/complex-closure-inference.md +++ b/userdocs/diagnostics/complex-closure-inference.md @@ -10,7 +10,7 @@ let doubler = { If a closure body is not a single expression, it will not be considered when inferring the closure type. This is consistent with how type inference works in other parts of the language, where it proceeds one statement at a time. For example, in the following code an error will be reported because the type of `evenDoubler` cannot be inferred from its surrounding context and no signature was provided: ```swift -// error: unable to infer complex closure return type; add explicit type to disambiguate +// error: cannot infer return type for closure with multiple statements; add explicit type to disambiguate let evenDoubler = { x in if x.isMultiple(of: 2) { return x * 2 diff --git a/validation-test/compiler_crashers_2_fixed/0119-rdar33613329.swift b/validation-test/compiler_crashers_2_fixed/0119-rdar33613329.swift index 84d1ffc73c1..176928ec678 100644 --- a/validation-test/compiler_crashers_2_fixed/0119-rdar33613329.swift +++ b/validation-test/compiler_crashers_2_fixed/0119-rdar33613329.swift @@ -43,4 +43,4 @@ struct X { var y: Int = 0 } var x = X() x ~> \X.y ≈> { a in a += 1; return 3 } // expected-error@-1 {{referencing operator function '~>' on 'P' requires that 'M, R>' conform to 'P'}} -// expected-error@-2 {{unable to infer complex closure return type; add explicit type to disambiguate}} +// expected-error@-2 {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}}