Skip to content

Commit 4c56001

Browse files
kddnewtonmatzbot
authored andcommitted
[ruby/prism] Fix up newlines in newline-delimited-literals
When you have a %-literal that is delimited by newlines, and you are also interpolating a heredoc into that literal, then both concepts will attempt to add the same newline to the newline list. ruby/prism@c831abb888
1 parent bcdad7f commit 4c56001

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

prism/prism.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12249,7 +12249,13 @@ parser_lex(pm_parser_t *parser) {
1224912249
size_t eol_length = match_eol_at(parser, breakpoint);
1225012250
if (eol_length) {
1225112251
parser->current.end = breakpoint + eol_length;
12252-
pm_newline_list_append(&parser->newline_list, parser->current.end - 1);
12252+
12253+
// Track the newline if we're not in a heredoc that
12254+
// would have already have added the newline to the
12255+
// list.
12256+
if (parser->heredoc_end == NULL) {
12257+
pm_newline_list_append(&parser->newline_list, parser->current.end - 1);
12258+
}
1225312259
} else {
1225412260
parser->current.end = breakpoint + 1;
1225512261
}
@@ -12503,7 +12509,13 @@ parser_lex(pm_parser_t *parser) {
1250312509
size_t eol_length = match_eol_at(parser, breakpoint);
1250412510
if (eol_length) {
1250512511
parser->current.end = breakpoint + eol_length;
12506-
pm_newline_list_append(&parser->newline_list, parser->current.end - 1);
12512+
12513+
// Track the newline if we're not in a heredoc that
12514+
// would have already have added the newline to the
12515+
// list.
12516+
if (parser->heredoc_end == NULL) {
12517+
pm_newline_list_append(&parser->newline_list, parser->current.end - 1);
12518+
}
1250712519
} else {
1250812520
parser->current.end = breakpoint + 1;
1250912521
}

0 commit comments

Comments
 (0)