mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #29735 from owenv/multiple-varargs
[SE-0284] Allow Multiple Variadic Parameters in Functions, Subscripts, and Initializers
This commit is contained in:
@@ -574,7 +574,6 @@ mapParsedParameters(Parser &parser,
|
||||
// Collect the elements of the tuple patterns for argument and body
|
||||
// parameters.
|
||||
SmallVector<ParamDecl*, 4> elements;
|
||||
SourceLoc ellipsisLoc;
|
||||
|
||||
for (auto ¶m : params) {
|
||||
// Whether the provided name is API by default depends on the parameter
|
||||
@@ -625,27 +624,26 @@ mapParsedParameters(Parser &parser,
|
||||
}
|
||||
|
||||
// Warn when an unlabeled parameter follows a variadic parameter
|
||||
if (ellipsisLoc.isValid() && elements.back()->isVariadic() &&
|
||||
param.FirstName.empty()) {
|
||||
parser.diagnose(param.FirstNameLoc,
|
||||
diag::unlabeled_parameter_following_variadic_parameter);
|
||||
if (!elements.empty() && elements.back()->isVariadic() && argName.empty()) {
|
||||
// Closure parameters can't have external labels, so use a more specific
|
||||
// diagnostic.
|
||||
if (paramContext == Parser::ParameterContextKind::Closure)
|
||||
parser.diagnose(
|
||||
param.FirstNameLoc,
|
||||
diag::closure_unlabeled_parameter_following_variadic_parameter);
|
||||
else
|
||||
parser.diagnose(param.FirstNameLoc,
|
||||
diag::unlabeled_parameter_following_variadic_parameter);
|
||||
}
|
||||
|
||||
// If this parameter had an ellipsis, check whether it's the last parameter.
|
||||
if (param.EllipsisLoc.isValid()) {
|
||||
if (ellipsisLoc.isValid()) {
|
||||
parser.diagnose(param.EllipsisLoc, diag::multiple_parameter_ellipsis)
|
||||
.highlight(ellipsisLoc)
|
||||
.fixItRemove(param.EllipsisLoc);
|
||||
|
||||
param.EllipsisLoc = SourceLoc();
|
||||
} else if (!result->getTypeRepr()) {
|
||||
// If this parameter had an ellipsis, check it has a TypeRepr.
|
||||
if (param.EllipsisLoc.isValid()) {
|
||||
if (!result->getTypeRepr()) {
|
||||
parser.diagnose(param.EllipsisLoc, diag::untyped_pattern_ellipsis)
|
||||
.highlight(result->getSourceRange());
|
||||
|
||||
param.EllipsisLoc = SourceLoc();
|
||||
} else {
|
||||
ellipsisLoc = param.EllipsisLoc;
|
||||
result->setVariadic();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user