File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -3082,9 +3082,18 @@ Expr *Parser::parseExprAnonClosureArg() {
3082
3082
diagnose (Loc, diag::anon_closure_arg_not_in_closure);
3083
3083
return new (Context) ErrorExpr (Loc);
3084
3084
}
3085
- // When the closure already has explicit parameters, offer their names as
3086
- // replacements .
3085
+
3086
+ // Check whether the closure already has explicit parameters .
3087
3087
if (auto *params = closure->getParameters ()) {
3088
+ // If the explicit parameters are due to the anonymous parameters having
3089
+ // already been set, retrieve the parameter from there.
3090
+ if (closure->hasAnonymousClosureVars () && ArgNo < params->size ()) {
3091
+ return new (Context) DeclRefExpr (params->get (ArgNo), DeclNameLoc (Loc),
3092
+ /* Implicit=*/ false );
3093
+ }
3094
+
3095
+ // If the closure already has an explicit parameter, offer its name as
3096
+ // a replacement.
3088
3097
if (ArgNo < params->size () && params->get (ArgNo)->hasName ()) {
3089
3098
auto paramName = params->get (ArgNo)->getNameStr ();
3090
3099
diagnose (Loc, diag::anon_closure_arg_in_closure_with_args_typo, paramName)
Original file line number Diff line number Diff line change @@ -219,6 +219,13 @@ func testStringifyWithLocalTypes() {
219
219
} )
220
220
}
221
221
222
+ // Stringify in closures that have anonymous parameters.
223
+ func testStringifyWithAnonymousParameters( ) {
224
+ {
225
+ _ = #stringify ( $0 + $1)
226
+ } ( 1 , 2 )
227
+ }
228
+
222
229
func maybeThrowing( ) throws -> Int { 5 }
223
230
224
231
#if TEST_DIAGNOSTICS
You can’t perform that action at this time.
0 commit comments