Skip to content

Commit 337084e

Browse files
committed
[Diagnostics] Always use the parameter name for closure parameter diagnostics,
because the $ prefix does not indicate that the parameter is anonymous.
1 parent 3ae349c commit 337084e

File tree

7 files changed

+8
-18
lines changed

7 files changed

+8
-18
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6769,13 +6769,9 @@ bool UnableToInferClosureParameterType::diagnoseAsError() {
67696769
llvm::SmallString<16> id;
67706770
llvm::raw_svector_ostream OS(id);
67716771

6772-
if (PD->isAnonClosureParam()) {
6773-
OS << "$" << paramIdx;
6774-
} else {
6775-
OS << "'" << PD->getParameterName() << "'";
6776-
}
6772+
OS << "'" << PD->getParameterName() << "'";
67776773

6778-
auto loc = PD->isAnonClosureParam() ? getLoc() : PD->getLoc();
6774+
auto loc = PD->isImplicit() ? getLoc() : PD->getLoc();
67796775
emitDiagnosticAt(loc, diag::cannot_infer_closure_parameter_type, OS.str());
67806776
return true;
67816777
}

lib/Sema/CSFix.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,11 +1533,7 @@ std::string SpecifyClosureParameterType::getName() const {
15331533
auto *PD = closure->getParameters()->get(paramLoc.getIndex());
15341534

15351535
OS << "specify type for parameter ";
1536-
if (PD->isAnonClosureParam()) {
1537-
OS << "$" << paramLoc.getIndex();
1538-
} else {
1539-
OS << "'" << PD->getParameterName() << "'";
1540-
}
1536+
OS << "'" << PD->getParameterName() << "'";
15411537

15421538
return OS.str();
15431539
}

test/Constraints/closures.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ struct S_3520 {
499499
func sr3520_set_via_closure<S, T>(_ closure: (inout S, T) -> ()) {} // expected-note {{in call to function 'sr3520_set_via_closure'}}
500500
sr3520_set_via_closure({ $0.number1 = $1 })
501501
// expected-error@-1 {{generic parameter 'S' could not be inferred}}
502-
// expected-error@-2 {{unable to infer type of a closure parameter $1 in the current context}}
502+
// expected-error@-2 {{unable to infer type of a closure parameter '$1' in the current context}}
503503

504504
// SR-3073: UnresolvedDotExpr in single expression closure
505505

test/Constraints/diagnostics.swift

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

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

301301

302302

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{{unable to infer type of a closure parameter '$0' in the current context}}
77
}
88

test/Sema/property_wrapper_parameter_invalid.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ func testInvalidWrapperInference() {
224224
S<Int>.test({ $value in })
225225

226226
func testGenericClosure<T>(_ closure: T) {}
227-
// FIXME: the following error should use the name of the closure parameter.
228-
// It's not anonymous, even though it starts with $
229-
// expected-error@+1 {{unable to infer type of a closure parameter $0 in the current context}}
227+
// expected-error@+1 {{unable to infer type of a closure parameter '$value' in the current context}}
230228
testGenericClosure { $value in }
231229
testGenericClosure { ($value: ProjectionWrapper<Int>) in } // okay
232230

test/expr/closure/anonymous.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func variadic() {
3232
// FIXME: Problem here is related to multi-statement closure body not being type-checked together with
3333
// enclosing context. We could have inferred `$0` to be `[Int]` if `let` was a part of constraint system.
3434
takesVariadicGeneric({let _: [Int] = $0})
35-
// expected-error@-1 {{unable to infer type of a closure parameter $0 in the current context}}
35+
// expected-error@-1 {{unable to infer type of a closure parameter '$0' in the current context}}
3636

3737
takesVariadicIntInt({_ = $0; takesIntArray($1)})
3838
takesVariadicIntInt({_ = $0; let _: [Int] = $1})

0 commit comments

Comments
 (0)