mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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.
This commit is contained in:
parent
5fb574ae4e
commit
2a6917b463
2 changed files with 6 additions and 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 inline int
|
||||||
static_literal_node_pair_p(const NODE *node, const rb_iseq_t *iseq)
|
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
|
static int
|
||||||
|
|
|
@ -184,6 +184,11 @@ class TestRubyLiteral < Test::Unit::TestCase
|
||||||
list.each { |str| assert_predicate str, :frozen? }
|
list.each { |str| assert_predicate str, :frozen? }
|
||||||
end
|
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
|
if defined?(RubyVM::InstructionSequence.compile_option) and
|
||||||
RubyVM::InstructionSequence.compile_option.key?(:debug_frozen_string_literal)
|
RubyVM::InstructionSequence.compile_option.key?(:debug_frozen_string_literal)
|
||||||
def test_debug_frozen_string
|
def test_debug_frozen_string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue