Skip to content

Commit 4edefa8

Browse files
authored
Merge pull request #27820 from CodaFi/valid-the-impaler
2 parents e25e500 + dc63923 commit 4edefa8

File tree

6 files changed

+11
-33
lines changed

6 files changed

+11
-33
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,6 @@ ERROR(expected_parameter_colon,PointsToFirstBadToken,
870870
"expected ':' following argument label and parameter name", ())
871871
ERROR(expected_assignment_instead_of_comparison_operator,none,
872872
"expected '=' instead of '==' to assign default value for parameter", ())
873-
ERROR(missing_parameter_type,PointsToFirstBadToken,
874-
"parameter requires an explicit type", ())
875873
ERROR(multiple_parameter_ellipsis,none,
876874
"only a single variadic parameter '...' is permitted", ())
877875
ERROR(parameter_vararg_default,none,

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4933,12 +4933,6 @@ void Parser::ParsedAccessors::record(Parser &P, AbstractStorageDecl *storage,
49334933
storage->setAccessors(LBLoc, Accessors, RBLoc);
49344934
}
49354935

4936-
static void flagInvalidAccessor(AccessorDecl *func) {
4937-
if (func) {
4938-
func->setInvalid();
4939-
}
4940-
}
4941-
49424936
static void diagnoseConflictingAccessors(Parser &P, AccessorDecl *first,
49434937
AccessorDecl *&second) {
49444938
if (!second) return;
@@ -4949,7 +4943,7 @@ static void diagnoseConflictingAccessors(Parser &P, AccessorDecl *first,
49494943
P.diagnose(first->getLoc(), diag::previous_accessor,
49504944
getAccessorNameForDiagnostic(first, /*article*/ false),
49514945
/*already*/ false);
4952-
flagInvalidAccessor(second);
4946+
second->setInvalid();
49534947
}
49544948

49554949
template <class... DiagArgs>
@@ -4959,11 +4953,11 @@ static void diagnoseAndIgnoreObservers(Parser &P,
49594953
typename std::enable_if<true, DiagArgs>::type... args) {
49604954
if (auto &accessor = accessors.WillSet) {
49614955
P.diagnose(accessor->getLoc(), diagnostic, /*willSet*/ 0, args...);
4962-
flagInvalidAccessor(accessor);
4956+
accessor->setInvalid();
49634957
}
49644958
if (auto &accessor = accessors.DidSet) {
49654959
P.diagnose(accessor->getLoc(), diagnostic, /*didSet*/ 1, args...);
4966-
flagInvalidAccessor(accessor);
4960+
accessor->setInvalid();
49674961
}
49684962
}
49694963

@@ -4975,7 +4969,7 @@ void Parser::ParsedAccessors::classify(Parser &P, AbstractStorageDecl *storage,
49754969
// was invalid.
49764970
if (invalid) {
49774971
for (auto accessor : Accessors) {
4978-
flagInvalidAccessor(accessor);
4972+
accessor->setInvalid();
49794973
}
49804974
}
49814975

lib/Parse/ParseExpr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,8 +2656,6 @@ parseClosureSignatureIfPresent(SmallVectorImpl<CaptureListEntry> &captureList,
26562656
// to detect any tuple splat or destructuring as early as
26572657
// possible and give a proper fix-it. See SE-0110 for more details.
26582658
auto isTupleDestructuring = [](ParamDecl *param) -> bool {
2659-
if (!param->isInvalid())
2660-
return false;
26612659
if (auto *typeRepr = param->getTypeRepr())
26622660
return !param->hasName() && isa<TupleTypeRepr>(typeRepr);
26632661
return false;

lib/Parse/ParsePattern.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
327327
// was invalid. Remember that.
328328
if (type.isParseError() && !type.hasCodeCompletion())
329329
param.isInvalid = true;
330+
} else if (paramContext != Parser::ParameterContextKind::Closure) {
331+
diagnose(Tok, diag::expected_parameter_colon);
332+
param.isInvalid = true;
330333
}
331334
} else {
332335
// Otherwise, we have invalid code. Check to see if this looks like a
@@ -358,8 +361,6 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
358361
// on is most likely argument destructuring, we are going
359362
// to diagnose that after all of the parameters are parsed.
360363
if (param.Type) {
361-
// Mark current parameter as invalid so it is possible
362-
// to diagnose it as destructuring of the closure parameter list.
363364
param.isInvalid = true;
364365
if (!isClosure) {
365366
// Unnamed parameters must be written as "_: Type".
@@ -478,12 +479,6 @@ mapParsedParameters(Parser &parser,
478479
parser.CurDeclContext);
479480
param->getAttrs() = paramInfo.Attrs;
480481

481-
auto setInvalid = [&]{
482-
if (param->isInvalid())
483-
return;
484-
param->setInvalid();
485-
};
486-
487482
bool parsingEnumElt
488483
= (paramContext == Parser::ParameterContextKind::EnumElement);
489484
// If we're not parsing an enum case, lack of a SourceLoc for both
@@ -493,7 +488,7 @@ mapParsedParameters(Parser &parser,
493488

494489
// If we diagnosed this parameter as a parse error, propagate to the decl.
495490
if (paramInfo.isInvalid)
496-
setInvalid();
491+
param->setInvalid();
497492

498493
// If a type was provided, create the type for the parameter.
499494
if (auto type = paramInfo.Type) {
@@ -524,13 +519,6 @@ mapParsedParameters(Parser &parser,
524519
// or typealias with underlying function type.
525520
param->setAutoClosure(attrs.has(TypeAttrKind::TAK_autoclosure));
526521
}
527-
} else if (paramContext != Parser::ParameterContextKind::Closure) {
528-
// Non-closure parameters require a type.
529-
if (!param->isInvalid())
530-
parser.diagnose(param->getLoc(), diag::missing_parameter_type);
531-
532-
param->setSpecifier(ParamSpecifier::Default);
533-
setInvalid();
534522
} else if (paramInfo.SpecifierLoc.isValid()) {
535523
StringRef specifier;
536524
switch (paramInfo.SpecifierKind) {

test/Parse/invalid.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protocol Animal<Food> { // expected-error {{protocols do not allow generic para
7676
// SR-573 - Crash with invalid parameter declaration
7777
class Starfish {}
7878
struct Salmon {}
79-
func f573(s Starfish, // expected-error {{parameter requires an explicit type}}
79+
func f573(s Starfish, // expected-error {{expected ':' following argument label and parameter name}}
8080
_ ss: Salmon) -> [Int] {}
8181
func g573() { f573(Starfish(), Salmon()) }
8282

@@ -89,7 +89,7 @@ func SR979b(inout inout b: Int) {} // expected-error {{inout' before a parameter
8989
// expected-error@-1 {{parameter must not have multiple '__owned', 'inout', or '__shared' specifiers}} {{19-25=}}
9090
func SR979d(let let a: Int) {} // expected-warning {{'let' in this position is interpreted as an argument label}} {{13-16=`let`}}
9191
// expected-error @-1 {{expected ',' separator}} {{20-20=,}}
92-
// expected-error @-2 {{parameter requires an explicit type}}
92+
// expected-error @-2 {{expected ':' following argument label and parameter name}}
9393
// expected-warning @-3 {{extraneous duplicate parameter name; 'let' already has an argument label}} {{13-17=}}
9494
func SR979e(inout x: inout String) {} // expected-error {{parameter must not have multiple '__owned', 'inout', or '__shared' specifiers}} {{13-18=}}
9595
func SR979g(inout i: inout Int) {} // expected-error {{parameter must not have multiple '__owned', 'inout', or '__shared' specifiers}} {{13-18=}}

test/Sema/immutability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func testSelectorStyleArguments1(_ x: Int, bar y: Int) {
370370
func testSelectorStyleArguments2(let x: Int, // expected-warning {{'let' in this position is interpreted as an argument label}}{{34-37=`let`}}
371371
let bar y: Int) { // expected-warning {{'let' in this position is interpreted as an argument label}}{{34-37=`let`}}
372372
// expected-error @-1 {{expected ',' separator}}
373-
// expected-error @-2 {{parameter requires an explicit type}}
373+
// expected-error @-2 {{expected ':' following argument label and parameter name}}
374374
}
375375
func testSelectorStyleArguments3(_ x: Int, bar y: Int) {
376376
++x // expected-error {{cannot pass immutable value to mutating operator: 'x' is a 'let' constant}}

0 commit comments

Comments
 (0)