@@ -5525,25 +5525,37 @@ Parser::parseDeclInfixOperator(SourceLoc OperatorLoc, Identifier Name,
5525
5525
SourceLoc AssociativityLoc, AssociativityValueLoc,
5526
5526
PrecedenceLoc, PrecedenceValueLoc,
5527
5527
AssignmentLoc;
5528
-
5528
+
5529
+ auto ErrReturnFunc = [&] () {
5530
+ skipUntilDeclRBrace ();
5531
+ assert (Tok.getKind () == tok::r_brace);
5532
+ SourceLoc RBraceLoc = Tok.getLoc ();
5533
+ auto Res = new (Context)
5534
+ InfixOperatorDecl (CurDeclContext, OperatorLoc, Name, NameLoc, LBraceLoc,
5535
+ AssociativityLoc.isInvalid (), AssociativityLoc,
5536
+ AssociativityValueLoc, PrecedenceLoc.isInvalid (),
5537
+ PrecedenceLoc, PrecedenceValueLoc,
5538
+ AssignmentLoc.isInvalid (), AssignmentLoc,
5539
+ RBraceLoc,
5540
+ InfixData (precedence, associativity, assignment));
5541
+ Res->getAttrs () = Attributes;
5542
+ return makeParserErrorResult (Res);
5543
+ };
5529
5544
while (!Tok.is (tok::r_brace)) {
5530
5545
if (!Tok.is (tok::identifier)) {
5531
5546
diagnose (Tok, diag::expected_operator_attribute);
5532
- skipUntilDeclRBrace ();
5533
- return nullptr ;
5547
+ return ErrReturnFunc ();
5534
5548
}
5535
5549
5536
5550
if (Tok.getText ().equals (" associativity" )) {
5537
5551
if (AssociativityLoc.isValid ()) {
5538
5552
diagnose (Tok, diag::operator_associativity_redeclared);
5539
- skipUntilDeclRBrace ();
5540
- return nullptr ;
5553
+ return ErrReturnFunc ();
5541
5554
}
5542
5555
AssociativityLoc = consumeToken ();
5543
5556
if (!Tok.is (tok::identifier)) {
5544
5557
diagnose (Tok, diag::expected_infix_operator_associativity);
5545
- skipUntilDeclRBrace ();
5546
- return nullptr ;
5558
+ return ErrReturnFunc ();
5547
5559
}
5548
5560
auto parsedAssociativity
5549
5561
= llvm::StringSwitch<Optional<Associativity>>(Tok.getText ())
@@ -5553,8 +5565,7 @@ Parser::parseDeclInfixOperator(SourceLoc OperatorLoc, Identifier Name,
5553
5565
.Default (None);
5554
5566
if (!parsedAssociativity) {
5555
5567
diagnose (Tok, diag::unknown_infix_operator_associativity, Tok.getText ());
5556
- skipUntilDeclRBrace ();
5557
- return nullptr ;
5568
+ return ErrReturnFunc ();
5558
5569
}
5559
5570
associativity = *parsedAssociativity;
5560
5571
@@ -5565,14 +5576,12 @@ Parser::parseDeclInfixOperator(SourceLoc OperatorLoc, Identifier Name,
5565
5576
if (Tok.getText ().equals (" precedence" )) {
5566
5577
if (PrecedenceLoc.isValid ()) {
5567
5578
diagnose (Tok, diag::operator_precedence_redeclared);
5568
- skipUntilDeclRBrace ();
5569
- return nullptr ;
5579
+ return ErrReturnFunc ();
5570
5580
}
5571
5581
PrecedenceLoc = consumeToken ();
5572
5582
if (!Tok.is (tok::integer_literal)) {
5573
5583
diagnose (Tok, diag::expected_infix_operator_precedence);
5574
- skipUntilDeclRBrace ();
5575
- return nullptr ;
5584
+ return ErrReturnFunc ();
5576
5585
}
5577
5586
if (Tok.getText ().getAsInteger (0 , precedence)) {
5578
5587
diagnose (Tok, diag::invalid_infix_operator_precedence);
@@ -5586,17 +5595,15 @@ Parser::parseDeclInfixOperator(SourceLoc OperatorLoc, Identifier Name,
5586
5595
if (Tok.getText ().equals (" assignment" )) {
5587
5596
if (AssignmentLoc.isValid ()) {
5588
5597
diagnose (Tok, diag::operator_assignment_redeclared);
5589
- skipUntilDeclRBrace ();
5590
- return nullptr ;
5598
+ return ErrReturnFunc ();
5591
5599
}
5592
5600
AssignmentLoc = consumeToken ();
5593
5601
assignment = true ;
5594
5602
continue ;
5595
5603
}
5596
5604
5597
5605
diagnose (Tok, diag::unknown_infix_operator_attribute, Tok.getText ());
5598
- skipUntilDeclRBrace ();
5599
- return nullptr ;
5606
+ return ErrReturnFunc ();
5600
5607
}
5601
5608
5602
5609
SourceLoc RBraceLoc = Tok.getLoc ();
0 commit comments