@@ -140,11 +140,11 @@ Parser::parseGenericParameters(SourceLoc LAngleLoc) {
140140
141141 // Parse the optional where-clause.
142142 SourceLoc WhereLoc;
143+ SourceLoc EndLoc;
143144 SmallVector<RequirementRepr, 4 > Requirements;
144- bool FirstTypeInComplete;
145145 if (Tok.is (tok::kw_where) &&
146- parseGenericWhereClause (WhereLoc, Requirements,
147- FirstTypeInComplete) .isErrorOrHasCompletion ()) {
146+ parseGenericWhereClause (WhereLoc, EndLoc, Requirements)
147+ .isErrorOrHasCompletion ()) {
148148 Invalid = true ;
149149 }
150150
@@ -261,16 +261,14 @@ Parser::diagnoseWhereClauseInGenericParamList(const GenericParamList *
261261// / same-type-requirement:
262262// / type-identifier '==' type
263263ParserStatus Parser::parseGenericWhereClause (
264- SourceLoc &WhereLoc,
264+ SourceLoc &WhereLoc, SourceLoc &EndLoc,
265265 SmallVectorImpl<RequirementRepr> &Requirements,
266- bool &FirstTypeInComplete,
267266 bool AllowLayoutConstraints) {
268267 SyntaxParsingContext ClauseContext (SyntaxContext,
269268 SyntaxKind::GenericWhereClause);
270269 ParserStatus Status;
271270 // Parse the 'where'.
272271 WhereLoc = consumeToken (tok::kw_where);
273- FirstTypeInComplete = false ;
274272 SyntaxParsingContext ReqListContext (SyntaxContext,
275273 SyntaxKind::GenericRequirementList);
276274 bool HasNextReq;
@@ -283,7 +281,7 @@ ParserStatus Parser::parseGenericWhereClause(
283281 if (Tok.is (tok::code_complete)) {
284282 if (CodeCompletion)
285283 CodeCompletion->completeGenericRequirement ();
286- consumeToken (tok::code_complete);
284+ EndLoc = consumeToken (tok::code_complete);
287285 Status.setHasCodeCompletionAndIsError ();
288286 break ;
289287 }
@@ -295,7 +293,6 @@ ParserStatus Parser::parseGenericWhereClause(
295293 if (FirstType.hasCodeCompletion ()) {
296294 BodyContext->setTransparent ();
297295 Status.setHasCodeCompletionAndIsError ();
298- FirstTypeInComplete = true ;
299296 }
300297
301298 if (FirstType.isNull ()) {
@@ -383,8 +380,10 @@ ParserStatus Parser::parseGenericWhereClause(
383380 }
384381 } while (HasNextReq);
385382
386- if (Requirements.empty ())
387- WhereLoc = SourceLoc ();
383+ if (!Requirements.empty ())
384+ EndLoc = Requirements.back ().getSourceRange ().End ;
385+ else if (EndLoc.isInvalid ())
386+ EndLoc = WhereLoc;
388387
389388 return Status;
390389}
@@ -396,31 +395,26 @@ parseFreestandingGenericWhereClause(GenericContext *genCtx) {
396395 assert (Tok.is (tok::kw_where) && " Shouldn't call this without a where" );
397396
398397 SmallVector<RequirementRepr, 4 > Requirements;
399- SourceLoc WhereLoc;
400- bool FirstTypeInComplete;
401- auto result = parseGenericWhereClause (WhereLoc, Requirements,
402- FirstTypeInComplete);
403- if (result.isErrorOrHasCompletion () || Requirements.empty ())
404- return result;
398+ SourceLoc WhereLoc, EndLoc;
399+ auto result = parseGenericWhereClause (WhereLoc, EndLoc, Requirements);
405400
406401 genCtx->setTrailingWhereClause (
407- TrailingWhereClause::create (Context, WhereLoc, Requirements));
402+ TrailingWhereClause::create (Context, WhereLoc, EndLoc, Requirements));
408403
409- return ParserStatus () ;
404+ return result ;
410405}
411406
412407// / Parse a where clause after a protocol or associated type declaration.
413408ParserStatus Parser::parseProtocolOrAssociatedTypeWhereClause (
414409 TrailingWhereClause *&trailingWhere, bool isProtocol) {
415410 assert (Tok.is (tok::kw_where) && " Shouldn't call this without a where" );
416- SourceLoc whereLoc;
411+ SourceLoc whereLoc, endLoc ;
417412 SmallVector<RequirementRepr, 4 > requirements;
418- bool firstTypeInComplete;
419413 auto whereStatus =
420- parseGenericWhereClause (whereLoc, requirements, firstTypeInComplete );
414+ parseGenericWhereClause (whereLoc, endLoc, requirements );
421415 if (whereStatus.isSuccess () && !whereStatus.hasCodeCompletion ()) {
422416 trailingWhere =
423- TrailingWhereClause::create (Context, whereLoc, requirements);
417+ TrailingWhereClause::create (Context, whereLoc, endLoc, requirements);
424418 } else if (whereStatus.hasCodeCompletion ()) {
425419 return whereStatus;
426420 }
0 commit comments