Skip to content

Commit dc63923

Browse files
committed
Restructure invalid parameter diagnostic
Diagnose the fact that we're missing a colon, not the fact that we're missing a type since that's actually what has gone wrong.
1 parent 961a1cf commit dc63923

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
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/ParsePattern.cpp

Lines changed: 3 additions & 7 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
@@ -516,13 +519,6 @@ mapParsedParameters(Parser &parser,
516519
// or typealias with underlying function type.
517520
param->setAutoClosure(attrs.has(TypeAttrKind::TAK_autoclosure));
518521
}
519-
} else if (paramContext != Parser::ParameterContextKind::Closure) {
520-
// Non-closure parameters require a type.
521-
if (!param->isInvalid())
522-
parser.diagnose(param->getLoc(), diag::missing_parameter_type);
523-
524-
param->setSpecifier(ParamSpecifier::Default);
525-
setInvalid();
526522
} else if (paramInfo.SpecifierLoc.isValid()) {
527523
StringRef specifier;
528524
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)