mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #24059 from sl/sl/sr-10293
Allow var / let as parameter names but provide a warning and fixit to add backticks.
This commit is contained in:
@@ -230,9 +230,9 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
||||
}
|
||||
}
|
||||
|
||||
// ('inout' | 'let' | 'var' | '__shared' | '__owned')?
|
||||
// ('inout' | '__shared' | '__owned')?
|
||||
bool hasSpecifier = false;
|
||||
while (Tok.isAny(tok::kw_inout, tok::kw_let, tok::kw_var) ||
|
||||
while (Tok.is(tok::kw_inout) ||
|
||||
(Tok.is(tok::identifier) &&
|
||||
(Tok.getRawText().equals("__shared") ||
|
||||
Tok.getRawText().equals("__owned")))) {
|
||||
@@ -254,10 +254,6 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
||||
// better fixits.
|
||||
param.SpecifierKind = VarDecl::Specifier::Owned;
|
||||
param.SpecifierLoc = consumeToken();
|
||||
} else {
|
||||
diagnose(Tok, diag::parameter_let_var_as_attr, Tok.getText())
|
||||
.fixItRemove(Tok.getLoc());
|
||||
consumeToken();
|
||||
}
|
||||
hasSpecifier = true;
|
||||
} else {
|
||||
@@ -268,7 +264,14 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
||||
consumeToken();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If let or var is being used as an argument label, allow it but
|
||||
// generate a warning.
|
||||
if (!isClosure && Tok.isAny(tok::kw_let, tok::kw_var)) {
|
||||
diagnose(Tok, diag::parameter_let_var_as_attr, Tok.getText())
|
||||
.fixItReplace(Tok.getLoc(), "`" + Tok.getText().str() + "`");
|
||||
}
|
||||
|
||||
if (startsParameterName(*this, isClosure)) {
|
||||
// identifier-or-none for the first name
|
||||
param.FirstNameLoc = consumeArgumentLabel(param.FirstName);
|
||||
|
||||
Reference in New Issue
Block a user