@@ -236,6 +236,9 @@ static V<ast_parameter_list> parse_parameter_list(Lexer& lex) {
236236 params.push_back (parse_parameter (lex, true ));
237237 while (lex.tok () == tok_comma) {
238238 lex.next ();
239+ if (lex.tok () == tok_clpar) { // trailing comma
240+ break ;
241+ }
239242 params.push_back (parse_parameter (lex, false ));
240243 }
241244 }
@@ -266,6 +269,9 @@ static V<ast_argument_list> parse_argument_list(Lexer& lex) {
266269 args.push_back (parse_argument (lex));
267270 while (lex.tok () == tok_comma) {
268271 lex.next ();
272+ if (lex.tok () == tok_clpar) { // trailing comma
273+ break ;
274+ }
269275 args.push_back (parse_argument (lex));
270276 }
271277 }
@@ -311,9 +317,15 @@ static AnyExprV parse_expr100(Lexer& lex) {
311317 std::vector<AnyExprV> items (1 , first);
312318 while (lex.tok () == tok_comma) {
313319 lex.next ();
320+ if (lex.tok () == tok_clpar) { // trailing comma
321+ break ;
322+ }
314323 items.emplace_back (parse_expr (lex));
315324 }
316325 lex.expect (tok_clpar, " `)`" );
326+ if (items.size () == 1 ) { // we can reach here for 1 element with trailing comma: `(item, )`
327+ return items[0 ]; // then just return item, not a 1-element tensor,
328+ } // since 1-element tensors won't be type compatible with item's type
317329 return createV<ast_tensor>(loc, std::move (items));
318330 }
319331 case tok_opbracket: {
@@ -325,6 +337,9 @@ static AnyExprV parse_expr100(Lexer& lex) {
325337 std::vector<AnyExprV> items (1 , parse_expr (lex));
326338 while (lex.tok () == tok_comma) {
327339 lex.next ();
340+ if (lex.tok () == tok_clbracket) { // trailing comma
341+ break ;
342+ }
328343 items.emplace_back (parse_expr (lex));
329344 }
330345 lex.expect (tok_clbracket, " `]`" );
@@ -952,6 +967,9 @@ static V<ast_annotation> parse_annotation(Lexer& lex) {
952967 args.push_back (parse_expr (lex));
953968 while (lex.tok () == tok_comma) {
954969 lex.next ();
970+ if (lex.tok () == tok_clpar) { // trailing comma
971+ break ;
972+ }
955973 args.push_back (parse_expr (lex));
956974 }
957975 lex.expect (tok_clpar, " `)`" );
0 commit comments