@@ -1906,9 +1906,7 @@ bool swift::diagnoseArgumentLabelError(ASTContext &ctx,
1906
1906
assert (oldName || newName && " We can't have oldName and newName out of "
1907
1907
" bounds, otherwise n would be smaller" );
1908
1908
1909
- if (oldName == newName ||
1910
- (argList.hasTrailingClosure && i == argList.args .size () - 1 &&
1911
- (numMissing > 0 || numExtra > 0 || numWrong > 0 )))
1909
+ if (oldName == newName || argList.isUnlabeledTrailingClosureIdx (i))
1912
1910
continue ;
1913
1911
1914
1912
if (!oldName.hasValue () && newName.hasValue ()) {
@@ -1988,11 +1986,17 @@ bool swift::diagnoseArgumentLabelError(ASTContext &ctx,
1988
1986
if (i < newNames.size ())
1989
1987
newName = newNames[i];
1990
1988
1991
- if (oldName == newName || (i == n- 1 && argList.hasTrailingClosure ))
1989
+ if (oldName == newName || argList.isUnlabeledTrailingClosureIdx (i ))
1992
1990
continue ;
1993
1991
1994
1992
if (newName.empty ()) {
1995
- // Delete the old name.
1993
+ // If this is a labeled trailing closure, we need to replace with '_'.
1994
+ if (argList.isLabeledTrailingClosureIdx (i)) {
1995
+ diag.fixItReplace (argList.labelLocs [i], " _" );
1996
+ continue ;
1997
+ }
1998
+
1999
+ // Otherwise, delete the old name.
1996
2000
diag.fixItRemoveChars (argList.labelLocs [i],
1997
2001
argList.args [i]->getStartLoc ());
1998
2002
continue ;
@@ -2006,7 +2010,10 @@ bool swift::diagnoseArgumentLabelError(ASTContext &ctx,
2006
2010
if (newNameIsReserved)
2007
2011
newStr += " `" ;
2008
2012
2009
- if (oldName.empty ()) {
2013
+ // If the argument was previously unlabeled, insert the new label. Note that
2014
+ // we don't do this for labeled trailing closures as they write unlabeled
2015
+ // args as '_:', and therefore need replacement.
2016
+ if (oldName.empty () && !argList.isLabeledTrailingClosureIdx (i)) {
2010
2017
// Insert the name.
2011
2018
newStr += " : " ;
2012
2019
diag.fixItInsert (argList.args [i]->getStartLoc (), newStr);
0 commit comments