Skip to content

Commit 2c93c55

Browse files
authored
Ensure main file has default coverage if required. (#7169)
* Extract common code for coverage setup.
1 parent 3e7fdf2 commit 2c93c55

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

iseq.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,13 +835,20 @@ iseq_setup_coverage(VALUE coverages, VALUE path, const rb_ast_body_t *ast, int l
835835
return Qnil;
836836
}
837837

838-
rb_iseq_t *
839-
rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent)
838+
static inline void
839+
iseq_new_setup_coverage(VALUE path, const rb_ast_body_t *ast, int line_offset)
840840
{
841841
VALUE coverages = rb_get_coverages();
842+
842843
if (RTEST(coverages)) {
843844
iseq_setup_coverage(coverages, path, ast, 0);
844845
}
846+
}
847+
848+
rb_iseq_t *
849+
rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent)
850+
{
851+
iseq_new_setup_coverage(path, ast, 0);
845852

846853
return rb_iseq_new_with_opt(ast, name, path, realpath, 0, parent, 0,
847854
ISEQ_TYPE_TOP, &COMPILE_OPTION_DEFAULT);
@@ -850,6 +857,8 @@ rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath
850857
rb_iseq_t *
851858
rb_iseq_new_main(const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt)
852859
{
860+
iseq_new_setup_coverage(path, ast, 0);
861+
853862
return rb_iseq_new_with_opt(ast, rb_fstring_lit("<main>"),
854863
path, realpath, 0,
855864
parent, 0, ISEQ_TYPE_MAIN, opt ? &COMPILE_OPTION_DEFAULT : &COMPILE_OPTION_FALSE);

0 commit comments

Comments
 (0)