Skip to content

Commit c297070

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 ef58f6a commit c297070

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
@@ -6770,13 +6770,9 @@ bool UnableToInferClosureParameterType::diagnoseAsError() {
67706770
llvm::SmallString<16> id;
67716771
llvm::raw_svector_ostream OS(id);
67726772

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

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

lib/Sema/CSFix.cpp

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

15471547
OS << "specify type for parameter ";
1548-
if (PD->isAnonClosureParam()) {
1549-
OS << "$" << paramLoc.getIndex();
1550-
} else {
1551-
OS << "'" << PD->getParameterName() << "'";
1552-
}
1548+
OS << "'" << PD->getParameterName() << "'";
15531549

15541550
return OS.str();
15551551
}

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)