Skip to content

Commit 743eefb

Browse files
authored
Merge pull request #66498 from slavapestov/reword-diagnostics-in-current-context
Sema: Reword diagnostics to say 'without a type annotation' instead of 'without more context'
2 parents 9b9d576 + 1957bd6 commit 743eefb

33 files changed

+60
-60
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ ERROR(no_candidates_match_argument_type,none,
275275
(StringRef, Type, unsigned))
276276

277277
ERROR(cannot_infer_closure_parameter_type,none,
278-
"unable to infer type of a closure parameter %0 in the current context",
278+
"cannot infer type of closure parameter %0 without a type annotation",
279279
(StringRef))
280280
ERROR(cannot_infer_closure_type,none,
281-
"unable to infer closure type in the current context", ())
281+
"unable to infer closure type without a type annotation", ())
282282
ERROR(cannot_infer_empty_closure_result_type,none,
283283
"cannot infer return type of empty closure", ())
284284
ERROR(cannot_infer_closure_result_type,none,
@@ -4163,7 +4163,7 @@ ERROR(could_not_infer_placeholder,none,
41634163
"could not infer type for placeholder", ())
41644164

41654165
ERROR(type_of_expression_is_ambiguous,none,
4166-
"type of expression is ambiguous without more context", ())
4166+
"type of expression is ambiguous without a type annotation", ())
41674167

41684168
ERROR(failed_to_produce_diagnostic,Fatal,
41694169
"failed to produce diagnostic for expression; "

test/Constraints/closures.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ do {
516516
func set_via_closure<T, U>(_ closure: (inout T, U) -> ()) {} // expected-note {{in call to function 'set_via_closure'}}
517517
set_via_closure({ $0.number1 = $1 })
518518
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
519-
// expected-error@-2 {{unable to infer type of a closure parameter '$1' in the current context}}
519+
// expected-error@-2 {{cannot infer type of closure parameter '$1' without a type annotation}}
520520

521521
func f2<T>(_ item: T, _ update: (inout T) -> Void) {
522522
var x = item
@@ -1052,12 +1052,12 @@ overloaded_with_default_and_autoclosure { 42 } // Ok
10521052
overloaded_with_default_and_autoclosure(42) // Ok
10531053

10541054
/// https://github.com/apple/swift/issues/55261
1055-
/// "error: type of expression is ambiguous without more context" in many cases
1055+
/// "error: type of expression is ambiguous without a type annotation" in many cases
10561056
/// where methods are missing.
10571057
do {
10581058
let _ = { a, b in }
1059-
// expected-error@-1 {{unable to infer type of a closure parameter 'a' in the current context}}
1060-
// expected-error@-2 {{unable to infer type of a closure parameter 'b' in the current context}}
1059+
// expected-error@-1 {{cannot infer type of closure parameter 'a' without a type annotation}}
1060+
// expected-error@-2 {{cannot infer type of closure parameter 'b' without a type annotation}}
10611061

10621062
_ = .a { b in } // expected-error {{cannot infer contextual base in reference to member 'a'}}
10631063

@@ -1078,7 +1078,7 @@ let explicitUnboundResult2: (Array<Bool>) -> Array<Int> = {
10781078
}
10791079
// FIXME: Should we prioritize the contextual result type and infer Array<Int>
10801080
// rather than using a type variable in these cases?
1081-
// expected-error@+1 {{unable to infer closure type in the current context}}
1081+
// expected-error@+1 {{unable to infer closure type without a type annotation}}
10821082
let explicitUnboundResult3: (Array<Bool>) -> Array<Int> = {
10831083
(arr: Array) -> Array in [true]
10841084
}

test/Constraints/construction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ extension S3 {
154154
let s3b = S3(maybe: s3a)
155155

156156
// https://github.com/apple/swift/issues/47820
157-
// Erroneous diagnostic: type of expression is ambiguous without more context
157+
// Erroneous diagnostic: type of expression is ambiguous without a type annotation
158158
do {
159159
class C {
160160
struct S {

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func r18800223(_ i : Int) {
297297
}
298298

299299
// <rdar://problem/21883806> Bogus "'_' can only appear in a pattern or on the left side of an assignment" is back
300-
_ = { $0 } // expected-error {{unable to infer type of a closure parameter '$0' in the current context}}
300+
_ = { $0 } // expected-error {{cannot infer type of closure parameter '$0' without a type annotation}}
301301

302302

303303

test/Constraints/diagnostics_swift4.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class C_45110: P_45110 {
2929

3030
let _ = S_45110(arg: [C_45110()]) // expected-error {{extraneous argument label 'arg:' in call}}
3131

32-
// rdar://problem/31898542 - Swift 4: 'type of expression is ambiguous without more context' errors, without a fixit
32+
// rdar://problem/31898542 - Swift 4: 'type of expression is ambiguous without a type annotation' errors, without a fixit
3333

3434
enum R31898542<T> {
3535
case success(T) // expected-note {{'success' declared here}}

test/Constraints/if_expr.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func testNil3(_ x: Bool) {
9090
}
9191
func testNil4(_ x: Bool) {
9292
// FIXME: Bad diagnostic (#63130)
93-
let _: _? = if x { nil } else { 42 } // expected-error {{type of expression is ambiguous without more context}}
93+
let _: _? = if x { nil } else { 42 } // expected-error {{type of expression is ambiguous without a type annotation}}
9494
}
9595

9696
enum F<T> {
@@ -137,7 +137,7 @@ struct SQ : Q {
137137

138138
func testAssociatedTypeReturn1() {
139139
func fn<T : Q>(_ fn: (T) -> T.X) {}
140-
fn { x in // expected-error {{unable to infer type of a closure parameter 'x' in the current context}}
140+
fn { x in // expected-error {{cannot infer type of closure parameter 'x' without a type annotation}}
141141
if .random() { "" } else { "" }
142142
}
143143
fn { (x: SQ) in

test/Constraints/one_way_closure_params.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
func testBasic() {
44
let _: (Float) -> Float = { $0 + 1 }
55

6-
let _ = { $0 + 1 } // expected-error{{unable to infer type of a closure parameter '$0' in the current context}}
6+
let _ = { $0 + 1 } // expected-error{{cannot infer type of closure parameter '$0' without a type annotation}}
77
}
88

test/Constraints/operator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func rdar60727310() {
284284
// FIXME: Bad diagnostic.
285285
func f_54877(_ e: Error) {
286286
func foo<T>(_ a: T, _ op: ((T, T) -> Bool)) {}
287-
foo(e, ==) // expected-error {{type of expression is ambiguous without more context}}
287+
foo(e, ==) // expected-error {{type of expression is ambiguous without a type annotation}}
288288
}
289289

290290
// rdar://problem/62054241 - Swift compiler crashes when passing < as the sort function in sorted(by:) and the type of the array is not comparable

test/Constraints/pack-expansion-expressions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ do {
475475
}
476476
}
477477

478-
// rdar://107675464 - misplaced `each` results in `type of expression is ambiguous without more context`
478+
// rdar://107675464 - misplaced `each` results in `type of expression is ambiguous without a type annotation`
479479
do {
480480
func test_correct_each<each T: P>(_ value: repeat each T) -> (repeat each T.A) {
481481
return (repeat (each value).makeA()) // Ok

test/Constraints/parameterized_existentials.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ protocol P<A> {
66

77
func f1(x: any P) -> any P<Int> {
88
// FIXME: Bad diagnostic
9-
return x // expected-error {{type of expression is ambiguous without more context}}
9+
return x // expected-error {{type of expression is ambiguous without a type annotation}}
1010
}
1111

1212
func f2(x: any P<Int>) -> any P {

0 commit comments

Comments
 (0)