summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Dementyev <dementiev.vm@gmail.com>2026-04-21 23:34:44 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2026-05-04 15:06:51 -0700
commit1ce2e79b13733f1f2d2bbc2fa9f2b447f6ddd207 (patch)
tree52d4a1fd232a4017c663c047a537237e6404cd3a
parent43c01a5f0c0f04c21c1a01471ad2ab068b6a65b5 (diff)
- iseq.c: fix passing frozen option to compile_file_prism
-rw-r--r--iseq.c18
-rw-r--r--test/ruby/test_iseq.rb14
2 files changed, 30 insertions, 2 deletions
diff --git a/iseq.c b/iseq.c
index 73cd5671c0..27aec9f0f7 100644
--- a/iseq.c
+++ b/iseq.c
@@ -1898,16 +1898,30 @@ iseqw_s_compile_file_prism(int argc, VALUE *argv, VALUE self)
rb_execution_context_t *ec = GET_EC();
VALUE v = rb_vm_push_frame_fname(ec, file);
+ make_compile_option(&option, opt);
+
pm_parse_result_t result = { 0 };
result.options.line = 1;
result.node.coverage_enabled = 1;
+ switch (option.frozen_string_literal) {
+ case ISEQ_FROZEN_STRING_LITERAL_UNSET:
+ break;
+ case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
+ pm_options_frozen_string_literal_set(&result.options, false);
+ break;
+ case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
+ pm_options_frozen_string_literal_set(&result.options, true);
+ break;
+ default:
+ rb_bug("iseqw_s_compile_file_prism: invalid frozen_string_literal=%d", option.frozen_string_literal);
+ break;
+ }
+
VALUE script_lines;
VALUE error = pm_load_parse_file(&result, file, ruby_vm_keep_script_lines ? &script_lines : NULL);
if (error == Qnil) {
- make_compile_option(&option, opt);
-
int error_state;
iseq_new_setup_coverage(file, (int) (result.node.parser->newline_list.size - 1));
rb_iseq_t *iseq = pm_iseq_new_with_opt(&result.node, rb_fstring_lit("<main>"),
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index fa716787fe..c43fc32b59 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -355,6 +355,20 @@ class TestISeq < Test::Unit::TestCase
assert_not_predicate(s4, :frozen?)
end
+ def test_frozen_string_literal_compile_option_file
+ Tempfile.create(%w[fsl .rb]) do |f|
+ f.write("['foo', 'foo', \"\#{$f}foo\", \"\#{'foo'}\"]\n")
+ f.flush
+ $f = 'f'
+ s1, s2, s3, s4 = RubyVM::InstructionSequence
+ .compile_file(f.path, frozen_string_literal: true).eval
+ assert_predicate(s1, :frozen?)
+ assert_predicate(s2, :frozen?)
+ assert_not_predicate(s3, :frozen?)
+ assert_not_predicate(s4, :frozen?)
+ end
+ end
+
# Safe call chain is not optimized when Coverage is running.
# So we can test it only when Coverage is not running.
def test_safe_call_chain