diff --git a/lib/Parse/ParsePattern.cpp b/lib/Parse/ParsePattern.cpp index 79e8241268cf..b3a2914cca77 100644 --- a/lib/Parse/ParsePattern.cpp +++ b/lib/Parse/ParsePattern.cpp @@ -67,10 +67,10 @@ void Parser::DefaultArgumentInfo::setFunctionContext( static ParserStatus parseDefaultArgument( Parser &P, Parser::DefaultArgumentInfo *defaultArgs, unsigned argIndex, Expr *&init, bool &hasInheritedDefaultArg, - Parser::ParameterContextKind paramContext) { + Parser::ParameterContextKind paramContext, tok assignmentTok) { SyntaxParsingContext DefaultArgContext(P.SyntaxContext, SyntaxKind::InitializerClause); - SourceLoc equalLoc = P.consumeToken(tok::equal); + SourceLoc equalLoc = P.consumeToken(assignmentTok); if (P.SF.Kind == SourceFileKind::Interface) { // Swift module interfaces don't synthesize inherited intializers and @@ -366,13 +366,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc, } else { // Otherwise, we're not sure what is going on, but this doesn't smell // like a parameter. - if (Tok.isBinaryOperator() && Tok.getText() == "==") { - diagnose(Tok, - diag::expected_assignment_instead_of_comparison_operator) - .fixItReplace(Tok.getLoc(), "="); - } else { - diagnose(Tok, diag::expected_parameter_name); - } + diagnose(Tok, diag::expected_parameter_name); param.isInvalid = true; param.FirstNameLoc = Tok.getLoc(); TokReceiver->registerTokenKindChange(param.FirstNameLoc, @@ -387,13 +381,20 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc, param.EllipsisLoc = consumeToken(); } - // ('=' expr)? - if (Tok.is(tok::equal)) { + // ('=' expr) or ('==' expr)? + bool isEqualBinaryOperator = + Tok.isBinaryOperator() && Tok.getText() == "=="; + if (Tok.is(tok::equal) || isEqualBinaryOperator) { SourceLoc EqualLoc = Tok.getLoc(); - status |= parseDefaultArgument(*this, defaultArgs, defaultArgIndex, - param.DefaultArg, - param.hasInheritedDefaultArg, - paramContext); + + if (isEqualBinaryOperator) { + diagnose(Tok, diag::expected_assignment_instead_of_comparison_operator) + .fixItReplace(EqualLoc, "="); + } + + status |= parseDefaultArgument( + *this, defaultArgs, defaultArgIndex, param.DefaultArg, + param.hasInheritedDefaultArg, paramContext, Tok.getKind()); if (param.EllipsisLoc.isValid() && param.DefaultArg) { // The range of the complete default argument. diff --git a/test/Parse/recovery.swift b/test/Parse/recovery.swift index 3b68e74cabd0..d8539012346f 100644 --- a/test/Parse/recovery.swift +++ b/test/Parse/recovery.swift @@ -817,6 +817,5 @@ func f() { // | SR-11006 -// expected-error@+2 {{expected '=' instead of '==' to assign default value for parameter}} {{21-23==}} -// expected-error@+1 {{expected ',' separator}} +// expected-error@+1 {{expected '=' instead of '==' to assign default value for parameter}} {{21-23==}} func SR11006(a: Int == 0) {}