diff --git a/test/yarp/comments_test.rb b/test/yarp/comments_test.rb index 5c49f7b86e..c95438c891 100644 --- a/test/yarp/comments_test.rb +++ b/test/yarp/comments_test.rb @@ -6,7 +6,10 @@ class CommentsTest < Test::Unit::TestCase include ::YARP::DSL def test_comment_inline - assert_comment "# comment", :inline, 0..9 + source = "# comment" + + assert_comment source, :inline, 0..9 + assert_equal [0], YARP.const_get(:Debug).newlines(source) end def test_comment_inline_def diff --git a/yarp/util/yp_newline_list.c b/yarp/util/yp_newline_list.c index ad9d99d0ab..de353acf62 100644 --- a/yarp/util/yp_newline_list.c +++ b/yarp/util/yp_newline_list.c @@ -30,6 +30,7 @@ yp_newline_list_append(yp_newline_list_t *list, const char *cursor) { if (list->offsets == NULL) return false; } + assert(*cursor == '\n'); assert(cursor >= list->start); size_t newline_offset = (size_t) (cursor - list->start + 1); assert(list->size == 0 || newline_offset > list->offsets[list->size - 1]); diff --git a/yarp/yarp.c b/yarp/yarp.c index d559163288..acf4f86a19 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -5389,7 +5389,7 @@ parser_lex(yp_parser_t *parser) { /* fallthrough */ case '\n': { if (parser->heredoc_end == NULL) { - yp_newline_list_append(&parser->newline_list, parser->current.end - 1); + yp_newline_list_check_append(&parser->newline_list, parser->current.end - 1); } else { parser_flush_heredoc_end(parser); }