1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Symbol#== should be able to be redefined

* vm.c (vm_init_redefined_flag): set redefinition flag for Symbol#==.
  The bug was introduced in r58895.

* test/ruby/test_symbol.rb: test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ktsj 2017-07-02 10:38:38 +00:00
parent b08892c4ae
commit 0ff27c4604
2 changed files with 13 additions and 1 deletions

View file

@ -514,4 +514,16 @@ class TestSymbol < Test::Unit::TestCase
assert_not_equal sym.to_sym.hash,
`#{ruby} -e 'puts #{sym.inspect}.to_sym.hash'`.to_i
end
def test_eq_can_be_redefined
assert_in_out_err([], <<-RUBY, ["foo"], [])
class Symbol
def ==(obj)
"foo"
end
end
puts :a == :a
RUBY
end
end

2
vm.c
View file

@ -1576,7 +1576,7 @@ vm_init_redefined_flag(void)
OP(MULT, MULT), (C(Integer), C(Float));
OP(DIV, DIV), (C(Integer), C(Float));
OP(MOD, MOD), (C(Integer), C(Float));
OP(Eq, EQ), (C(Integer), C(Float), C(String));
OP(Eq, EQ), (C(Integer), C(Float), C(String), C(Symbol));
OP(Eqq, EQQ), (C(Integer), C(Float), C(Symbol), C(String),
C(NilClass), C(TrueClass), C(FalseClass));
OP(LT, LT), (C(Integer), C(Float));