@@ -274,25 +274,31 @@ ParserStatus Parser::parseGenericWhereClause(
274
274
SyntaxKind::GenericRequirementList);
275
275
bool HasNextReq;
276
276
do {
277
- SyntaxParsingContext ReqContext (SyntaxContext, SyntaxContextKind::Syntax);
277
+ SyntaxParsingContext ReqContext (SyntaxContext,
278
+ SyntaxKind::GenericRequirement);
279
+ Optional<SyntaxParsingContext> BodyContext;
280
+ BodyContext.emplace (SyntaxContext);
281
+
278
282
// Parse the leading type. It doesn't necessarily have to be just a type
279
283
// identifier if we're dealing with a same-type constraint.
280
284
ParserResult<TypeRepr> FirstType = parseType ();
281
285
282
286
if (FirstType.hasCodeCompletion ()) {
287
+ BodyContext->setTransparent ();
283
288
Status.setHasCodeCompletion ();
284
289
FirstTypeInComplete = true ;
285
290
}
286
291
287
292
if (FirstType.isNull ()) {
293
+ BodyContext->setTransparent ();
288
294
Status.setIsParseError ();
289
295
break ;
290
296
}
291
297
292
298
if (Tok.is (tok::colon)) {
293
299
// A conformance-requirement.
294
300
SourceLoc ColonLoc = consumeToken ();
295
- ReqContext. setCreateSyntax (SyntaxKind::ConformanceRequirement);
301
+ BodyContext-> setCreateSyntax (SyntaxKind::ConformanceRequirement);
296
302
if (Tok.is (tok::identifier) &&
297
303
getLayoutConstraint (Context.getIdentifier (Tok.getText ()), Context)
298
304
->isKnownLayout ()) {
@@ -332,7 +338,7 @@ ParserStatus Parser::parseGenericWhereClause(
332
338
}
333
339
} else if ((Tok.isAnyOperator () && Tok.getText () == " ==" ) ||
334
340
Tok.is (tok::equal)) {
335
- ReqContext. setCreateSyntax (SyntaxKind::SameTypeRequirement);
341
+ BodyContext-> setCreateSyntax (SyntaxKind::SameTypeRequirement);
336
342
// A same-type-requirement
337
343
if (Tok.is (tok::equal)) {
338
344
diagnose (Tok, diag::requires_single_equal)
@@ -354,10 +360,12 @@ ParserStatus Parser::parseGenericWhereClause(
354
360
EqualLoc,
355
361
SecondType.get ()));
356
362
} else {
363
+ BodyContext->setTransparent ();
357
364
diagnose (Tok, diag::expected_requirement_delim);
358
365
Status.setIsParseError ();
359
366
break ;
360
367
}
368
+ BodyContext.reset ();
361
369
HasNextReq = consumeIf (tok::comma);
362
370
// If there's a comma, keep parsing the list.
363
371
} while (HasNextReq);
0 commit comments