diff options
author | Alan Wu <[email protected]> | 2024-02-20 16:45:59 -0500 |
---|---|---|
committer | Alan Wu <[email protected]> | 2024-02-20 21:00:54 -0500 |
commit | 2a6917b463fa4065f26aea44802e2e24cc494e4c (patch) | |
tree | e16dbdac08c84f921bb6fafad53f3069eebddbcc | |
parent | 5fb574ae4e35bdb3688c1c89128c74d24a4c5d23 (diff) |
Fix string value in hash literal being forced frozen
We should pass `false` for `hash_key` for value nodes. Credits to
`@kddnewton` for noticing and bisecting.
-rw-r--r-- | compile.c | 2 | ||||
-rw-r--r-- | test/ruby/test_literal.rb | 5 |
2 files changed, 6 insertions, 1 deletions
@@ -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 diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb index 00adbff731..72dcce04e1 100644 --- a/test/ruby/test_literal.rb +++ b/test/ruby/test_literal.rb @@ -184,6 +184,11 @@ class TestRubyLiteral < Test::Unit::TestCase 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 |