@@ -8987,28 +8987,44 @@ Parser::parseDeclMacroExpansion(ParseDeclOptions flags,
89878987 if (!macroNameRef)
89888988 return makeParserError ();
89898989
8990+ ParserStatus status;
8991+ SourceLoc leftAngleLoc, rightAngleLoc;
8992+ SmallVector<TypeRepr *, 8 > genericArgs;
8993+ if (canParseAsGenericArgumentList ()) {
8994+ auto genericArgsStatus = parseGenericArguments (
8995+ genericArgs, leftAngleLoc, rightAngleLoc);
8996+ status |= genericArgsStatus;
8997+ if (genericArgsStatus.isErrorOrHasCompletion ())
8998+ diagnose (leftAngleLoc, diag::while_parsing_as_left_angle_bracket);
8999+ }
9000+
89909001 ArgumentList *argList = nullptr ;
89919002 if (Tok.isFollowingLParen ()) {
89929003 auto result = parseArgumentList (tok::l_paren, tok::r_paren,
89939004 /* isExprBasic*/ false ,
89949005 /* allowTrailingClosure*/ true );
9006+ status |= result;
89959007 if (result.hasCodeCompletion ())
89969008 return makeParserCodeCompletionResult<MacroExpansionDecl>();
8997- if (result.isParseError ())
8998- return makeParserError ();
8999- argList = result.get ();
9009+ argList = result.getPtrOrNull ();
90009010 } else if (Tok.is (tok::l_brace)) {
90019011 SmallVector<Argument, 2 > trailingClosures;
9002- auto status = parseTrailingClosures (/* isExprBasic*/ false ,
9003- macroNameLoc.getSourceRange (),
9004- trailingClosures);
9005- if (status.isError () || trailingClosures.empty ())
9006- return makeParserError ();
9007- argList = ArgumentList::createParsed (Context, SourceLoc (),
9008- trailingClosures, SourceLoc (),
9009- /* trailingClosureIdx*/ 0 );
9012+ auto closuresStatus = parseTrailingClosures (/* isExprBasic*/ false ,
9013+ macroNameLoc.getSourceRange (),
9014+ trailingClosures);
9015+ status |= closuresStatus;
9016+
9017+ if (!trailingClosures.empty ()) {
9018+ argList = ArgumentList::createParsed (Context, SourceLoc (),
9019+ trailingClosures, SourceLoc (),
9020+ /* trailingClosureIdx*/ 0 );
9021+ }
90109022 }
90119023
9012- return makeParserResult (new (Context) MacroExpansionDecl (
9013- CurDeclContext, poundLoc, macroNameRef, macroNameLoc, argList));
9024+ return makeParserResult (
9025+ status,
9026+ new (Context) MacroExpansionDecl (
9027+ CurDeclContext, poundLoc, macroNameRef, macroNameLoc,
9028+ leftAngleLoc, Context.AllocateCopy (genericArgs), rightAngleLoc,
9029+ argList));
90149030}
0 commit comments