Skip to content

Commit 1f32990

Browse files
committed
Parse: Allow empty generic argument lists and generic argument lists containing ... in expression context
1 parent 1cf7d51 commit 1f32990

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,12 +1227,9 @@ Parser::parseExprPostfixSuffix(ParserResult<Expr> Result, bool isExprBasic,
12271227
if (argStat.isErrorOrHasCompletion())
12281228
diagnose(LAngleLoc, diag::while_parsing_as_left_angle_bracket);
12291229

1230-
// The result can be empty in error cases.
1231-
if (!args.empty()) {
1232-
Result = makeParserResult(
1233-
Result, UnresolvedSpecializeExpr::create(
1234-
Context, Result.get(), LAngleLoc, args, RAngleLoc));
1235-
}
1230+
Result = makeParserResult(
1231+
Result, UnresolvedSpecializeExpr::create(
1232+
Context, Result.get(), LAngleLoc, args, RAngleLoc));
12361233
}
12371234

12381235
continue;
@@ -2241,8 +2238,7 @@ ParserResult<Expr> Parser::parseExprIdentifier() {
22412238
if (argStatus.isErrorOrHasCompletion())
22422239
diagnose(LAngleLoc, diag::while_parsing_as_left_angle_bracket);
22432240

2244-
// The result can be empty in error cases.
2245-
hasGenericArgumentList = !args.empty();
2241+
hasGenericArgumentList = true;
22462242
}
22472243

22482244
if (name.getBaseName().isEditorPlaceholder()) {

lib/Parse/ParseType.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,13 +1365,18 @@ bool Parser::canParseGenericArguments() {
13651365
if (!startsWithLess(Tok))
13661366
return false;
13671367
consumeStartingLess();
1368-
1368+
1369+
if (startsWithGreater(Tok)) {
1370+
consumeStartingGreater();
1371+
return true;
1372+
}
1373+
13691374
do {
13701375
if (!canParseType())
13711376
return false;
13721377
// Parse the comma, if the list continues.
13731378
} while (consumeIf(tok::comma));
1374-
1379+
13751380
if (!startsWithGreater(Tok)) {
13761381
return false;
13771382
} else {
@@ -1454,19 +1459,20 @@ bool Parser::canParseType() {
14541459
break;
14551460
}
14561461

1457-
if (!isAtFunctionTypeArrow())
1458-
return true;
1459-
1460-
// Handle type-function if we have an '->' with optional
1461-
// 'async' and/or 'throws'.
1462-
while (isEffectsSpecifier(Tok))
1463-
consumeToken();
1462+
if (isAtFunctionTypeArrow()) {
1463+
// Handle type-function if we have an '->' with optional
1464+
// 'async' and/or 'throws'.
1465+
while (isEffectsSpecifier(Tok))
1466+
consumeToken();
14641467

1465-
if (!consumeIf(tok::arrow))
1466-
return false;
1467-
1468-
if (!canParseType())
1469-
return false;
1468+
if (!consumeIf(tok::arrow))
1469+
return false;
1470+
1471+
if (!canParseType())
1472+
return false;
1473+
1474+
return true;
1475+
}
14701476

14711477
// Parse pack expansion 'T...'.
14721478
if (Tok.isEllipsis()) {

0 commit comments

Comments
 (0)