diff --git a/iseq.c b/iseq.c index b68c230404..fa5f564fb3 100644 --- a/iseq.c +++ b/iseq.c @@ -1447,7 +1447,19 @@ iseqw_s_compile_prism(int argc, VALUE *argv, VALUE self) pm_options_line_set(&options, start_line); pm_parser_t parser; - pm_parser_init(&parser, (const uint8_t *) RSTRING_PTR(src), RSTRING_LEN(src), &options); + + if (RB_TYPE_P(src, T_FILE)) { + FilePathValue(src); + file = rb_fstring(src); /* rb_io_t->pathv gets frozen anyways */ + + pm_string_t input; + pm_string_mapped_init(&input, RSTRING_PTR(file)); + + pm_parser_init(&parser, pm_string_source(&input), pm_string_length(&input), &options); + } + else { + pm_parser_init(&parser, (const uint8_t *) RSTRING_PTR(src), RSTRING_LEN(src), &options); + } rb_iseq_t *iseq = iseq_alloc(); iseqw_s_compile_prism_compile(&parser, opt, iseq, file, path, start_line); diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index f05d067ac2..b0896511d8 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -798,4 +798,15 @@ class TestISeq < Test::Unit::TestCase result = RubyVM::InstructionSequence.load_from_binary(iseq.to_binary).eval assert_equal expected, result, proc {sprintf("expected: %x, result: %x", expected, result)} end + + def test_compile_prism_with_file + Tempfile.create(%w"test_iseq .rb") do |f| + f.puts "name = 'Prism'; puts 'hello" + f.close + + assert_nothing_raised(SyntaxError) { + RubyVM::InstructionSequence.compile_prism(f.path) + } + end + end end