@@ -67,10 +67,10 @@ void Parser::DefaultArgumentInfo::setFunctionContext(
67
67
static ParserStatus parseDefaultArgument (
68
68
Parser &P, Parser::DefaultArgumentInfo *defaultArgs, unsigned argIndex,
69
69
Expr *&init, bool &hasInheritedDefaultArg,
70
- Parser::ParameterContextKind paramContext) {
70
+ Parser::ParameterContextKind paramContext, tok assignmentTok ) {
71
71
SyntaxParsingContext DefaultArgContext (P.SyntaxContext ,
72
72
SyntaxKind::InitializerClause);
73
- SourceLoc equalLoc = P.consumeToken (tok::equal );
73
+ SourceLoc equalLoc = P.consumeToken (assignmentTok );
74
74
75
75
if (P.SF .Kind == SourceFileKind::Interface) {
76
76
// Swift module interfaces don't synthesize inherited intializers and
@@ -366,13 +366,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
366
366
} else {
367
367
// Otherwise, we're not sure what is going on, but this doesn't smell
368
368
// like a parameter.
369
- if (Tok.isBinaryOperator () && Tok.getText () == " ==" ) {
370
- diagnose (Tok,
371
- diag::expected_assignment_instead_of_comparison_operator)
372
- .fixItReplace (Tok.getLoc (), " =" );
373
- } else {
374
- diagnose (Tok, diag::expected_parameter_name);
375
- }
369
+ diagnose (Tok, diag::expected_parameter_name);
376
370
param.isInvalid = true ;
377
371
param.FirstNameLoc = Tok.getLoc ();
378
372
TokReceiver->registerTokenKindChange (param.FirstNameLoc ,
@@ -387,13 +381,20 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
387
381
param.EllipsisLoc = consumeToken ();
388
382
}
389
383
390
- // ('=' expr)?
391
- if (Tok.is (tok::equal)) {
384
+ // ('=' expr) or ('==' expr)?
385
+ bool isEqualBinaryOperator =
386
+ Tok.isBinaryOperator () && Tok.getText () == " ==" ;
387
+ if (Tok.is (tok::equal) || isEqualBinaryOperator) {
392
388
SourceLoc EqualLoc = Tok.getLoc ();
393
- status |= parseDefaultArgument (*this , defaultArgs, defaultArgIndex,
394
- param.DefaultArg ,
395
- param.hasInheritedDefaultArg ,
396
- paramContext);
389
+
390
+ if (isEqualBinaryOperator) {
391
+ diagnose (Tok, diag::expected_assignment_instead_of_comparison_operator)
392
+ .fixItReplace (EqualLoc, " =" );
393
+ }
394
+
395
+ status |= parseDefaultArgument (
396
+ *this , defaultArgs, defaultArgIndex, param.DefaultArg ,
397
+ param.hasInheritedDefaultArg , paramContext, Tok.getKind ());
397
398
398
399
if (param.EllipsisLoc .isValid () && param.DefaultArg ) {
399
400
// The range of the complete default argument.
0 commit comments