Skip to content

Commit

Permalink
Fix string value in hash literal being forced frozen
Browse files Browse the repository at this point in the history
We should pass `false` for `hash_key` for value nodes. Credits to
`@kddnewton` for noticing and bisecting.
  • Loading branch information
XrXr committed Feb 21, 2024
1 parent 5fb574a commit 2a6917b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compile.c
Expand Up @@ -4910,7 +4910,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int pop
static inline int
static_literal_node_pair_p(const NODE *node, const rb_iseq_t *iseq)
{
return RNODE_LIST(node)->nd_head && static_literal_node_p(RNODE_LIST(node)->nd_head, iseq, true) && static_literal_node_p(RNODE_LIST(RNODE_LIST(node)->nd_next)->nd_head, iseq, true);
return RNODE_LIST(node)->nd_head && static_literal_node_p(RNODE_LIST(node)->nd_head, iseq, true) && static_literal_node_p(RNODE_LIST(RNODE_LIST(node)->nd_next)->nd_head, iseq, false);
}

static int
Expand Down
5 changes: 5 additions & 0 deletions test/ruby/test_literal.rb
Expand Up @@ -184,6 +184,11 @@ def test_frozen_string_in_array_literal
list.each { |str| assert_predicate str, :frozen? }
end

def test_string_in_hash_literal
hash = eval("# frozen-string-literal: false\n""{foo: 'foo'}")
assert_not_predicate(hash[:foo], :frozen?)
end

if defined?(RubyVM::InstructionSequence.compile_option) and
RubyVM::InstructionSequence.compile_option.key?(:debug_frozen_string_literal)
def test_debug_frozen_string
Expand Down

0 comments on commit 2a6917b

Please sign in to comment.