@@ -140,11 +140,11 @@ Parser::parseGenericParameters(SourceLoc LAngleLoc) {
140
140
141
141
// Parse the optional where-clause.
142
142
SourceLoc WhereLoc;
143
+ SourceLoc EndLoc;
143
144
SmallVector<RequirementRepr, 4 > Requirements;
144
- bool FirstTypeInComplete;
145
145
if (Tok.is (tok::kw_where) &&
146
- parseGenericWhereClause (WhereLoc, Requirements,
147
- FirstTypeInComplete) .isErrorOrHasCompletion ()) {
146
+ parseGenericWhereClause (WhereLoc, EndLoc, Requirements)
147
+ .isErrorOrHasCompletion ()) {
148
148
Invalid = true ;
149
149
}
150
150
@@ -261,16 +261,14 @@ Parser::diagnoseWhereClauseInGenericParamList(const GenericParamList *
261
261
// / same-type-requirement:
262
262
// / type-identifier '==' type
263
263
ParserStatus Parser::parseGenericWhereClause (
264
- SourceLoc &WhereLoc,
264
+ SourceLoc &WhereLoc, SourceLoc &EndLoc,
265
265
SmallVectorImpl<RequirementRepr> &Requirements,
266
- bool &FirstTypeInComplete,
267
266
bool AllowLayoutConstraints) {
268
267
SyntaxParsingContext ClauseContext (SyntaxContext,
269
268
SyntaxKind::GenericWhereClause);
270
269
ParserStatus Status;
271
270
// Parse the 'where'.
272
271
WhereLoc = consumeToken (tok::kw_where);
273
- FirstTypeInComplete = false ;
274
272
SyntaxParsingContext ReqListContext (SyntaxContext,
275
273
SyntaxKind::GenericRequirementList);
276
274
bool HasNextReq;
@@ -283,7 +281,7 @@ ParserStatus Parser::parseGenericWhereClause(
283
281
if (Tok.is (tok::code_complete)) {
284
282
if (CodeCompletion)
285
283
CodeCompletion->completeGenericRequirement ();
286
- consumeToken (tok::code_complete);
284
+ EndLoc = consumeToken (tok::code_complete);
287
285
Status.setHasCodeCompletionAndIsError ();
288
286
break ;
289
287
}
@@ -295,7 +293,6 @@ ParserStatus Parser::parseGenericWhereClause(
295
293
if (FirstType.hasCodeCompletion ()) {
296
294
BodyContext->setTransparent ();
297
295
Status.setHasCodeCompletionAndIsError ();
298
- FirstTypeInComplete = true ;
299
296
}
300
297
301
298
if (FirstType.isNull ()) {
@@ -383,8 +380,10 @@ ParserStatus Parser::parseGenericWhereClause(
383
380
}
384
381
} while (HasNextReq);
385
382
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;
388
387
389
388
return Status;
390
389
}
@@ -396,31 +395,26 @@ parseFreestandingGenericWhereClause(GenericContext *genCtx) {
396
395
assert (Tok.is (tok::kw_where) && " Shouldn't call this without a where" );
397
396
398
397
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);
405
400
406
401
genCtx->setTrailingWhereClause (
407
- TrailingWhereClause::create (Context, WhereLoc, Requirements));
402
+ TrailingWhereClause::create (Context, WhereLoc, EndLoc, Requirements));
408
403
409
- return ParserStatus () ;
404
+ return result ;
410
405
}
411
406
412
407
// / Parse a where clause after a protocol or associated type declaration.
413
408
ParserStatus Parser::parseProtocolOrAssociatedTypeWhereClause (
414
409
TrailingWhereClause *&trailingWhere, bool isProtocol) {
415
410
assert (Tok.is (tok::kw_where) && " Shouldn't call this without a where" );
416
- SourceLoc whereLoc;
411
+ SourceLoc whereLoc, endLoc ;
417
412
SmallVector<RequirementRepr, 4 > requirements;
418
- bool firstTypeInComplete;
419
413
auto whereStatus =
420
- parseGenericWhereClause (whereLoc, requirements, firstTypeInComplete );
414
+ parseGenericWhereClause (whereLoc, endLoc, requirements );
421
415
if (whereStatus.isSuccess () && !whereStatus.hasCodeCompletion ()) {
422
416
trailingWhere =
423
- TrailingWhereClause::create (Context, whereLoc, requirements);
417
+ TrailingWhereClause::create (Context, whereLoc, endLoc, requirements);
424
418
} else if (whereStatus.hasCodeCompletion ()) {
425
419
return whereStatus;
426
420
}
0 commit comments