@@ -1176,8 +1176,16 @@ ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute(SourceLoc atLoc,
1176
1176
SmallVector<ParsedAutoDiffParameter, 8 > parameters;
1177
1177
1178
1178
// Parse trailing comma, if it exists, and check for errors.
1179
- auto consumeIfTrailingComma = [&]() -> bool {
1180
- if (!consumeIf (tok::comma)) return false ;
1179
+ auto consumeIfTrailingComma = [&](bool requireComma = false ) -> bool {
1180
+ if (!consumeIf (tok::comma)) {
1181
+ // If comma is required but does not exist and ')' has not been reached,
1182
+ // diagnose missing comma.
1183
+ if (requireComma && !Tok.is (tok::r_paren)) {
1184
+ diagnose (getEndOfPreviousLoc (), diag::expected_separator, " ," );
1185
+ return true ;
1186
+ }
1187
+ return false ;
1188
+ }
1181
1189
// Diagnose trailing comma before ')'.
1182
1190
if (Tok.is (tok::r_paren)) {
1183
1191
diagnose (Tok, diag::unexpected_separator, " ," );
@@ -1211,7 +1219,7 @@ ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute(SourceLoc atLoc,
1211
1219
baseType, original))
1212
1220
return makeParserError ();
1213
1221
}
1214
- if (consumeIfTrailingComma ())
1222
+ if (consumeIfTrailingComma (/* requireComma */ true ))
1215
1223
return makeParserError ();
1216
1224
// Parse the optional 'wrt' differentiability parameters clause.
1217
1225
if (isIdentifier (Tok, " wrt" ) &&
@@ -1250,8 +1258,16 @@ ParserResult<TransposeAttr> Parser::parseTransposeAttribute(SourceLoc atLoc,
1250
1258
SmallVector<ParsedAutoDiffParameter, 8 > parameters;
1251
1259
1252
1260
// Parse trailing comma, if it exists, and check for errors.
1253
- auto consumeIfTrailingComma = [&]() -> bool {
1254
- if (!consumeIf (tok::comma)) return false ;
1261
+ auto consumeIfTrailingComma = [&](bool requireComma = false ) -> bool {
1262
+ if (!consumeIf (tok::comma)) {
1263
+ // If comma is required but does not exist and ')' has not been reached,
1264
+ // diagnose missing comma.
1265
+ if (requireComma && !Tok.is (tok::r_paren)) {
1266
+ diagnose (Tok, diag::expected_separator, " ," );
1267
+ return true ;
1268
+ }
1269
+ return false ;
1270
+ }
1255
1271
// Diagnose trailing comma before ')'.
1256
1272
if (Tok.is (tok::r_paren)) {
1257
1273
diagnose (Tok, diag::unexpected_separator, " ," );
@@ -1286,7 +1302,7 @@ ParserResult<TransposeAttr> Parser::parseTransposeAttribute(SourceLoc atLoc,
1286
1302
baseType, original))
1287
1303
return makeParserError ();
1288
1304
}
1289
- if (consumeIfTrailingComma ())
1305
+ if (consumeIfTrailingComma (/* requireComma */ true ))
1290
1306
return makeParserError ();
1291
1307
// Parse the optional 'wrt' linearity parameters clause.
1292
1308
if (Tok.is (tok::identifier) && Tok.getText () == " wrt" &&
0 commit comments