Skip to content

Commit

Permalink
[PRISM] Use frozen flag on StringNode
Browse files Browse the repository at this point in the history
  • Loading branch information
jemmaissroff committed Dec 14, 2023
1 parent a18819e commit 8e1c148
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion prism_compile.c
Expand Up @@ -5189,7 +5189,12 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
if (!popped) {
pm_string_node_t *cast = (pm_string_node_t *) node;
VALUE value = parse_string_encoded(node, &cast->unescaped, parser);
ADD_INSN1(ret, &dummy_line_node, putstring, value);
if (node->flags & PM_STRING_FLAGS_FROZEN) {
ADD_INSN1(ret, &dummy_line_node, putobject, rb_str_freeze(value));
}
else {
ADD_INSN1(ret, &dummy_line_node, putstring, value);
}
}
return;
}
Expand Down
10 changes: 10 additions & 0 deletions test/ruby/test_compile_prism.rb
Expand Up @@ -607,6 +607,16 @@ def test_RegularExpressionNode

def test_StringNode
assert_prism_eval('"pit"')
assert_prism_eval('"a".frozen?')

frozen_source = <<-CODE
# frozen_string_literal: true
"a".frozen?
CODE
ruby_eval = RubyVM::InstructionSequence.compile(frozen_source).eval
prism_eval = RubyVM::InstructionSequence.compile_prism(frozen_source).eval

assert_equal ruby_eval, prism_eval
end

def test_SymbolNode
Expand Down

0 comments on commit 8e1c148

Please sign in to comment.