* vm_eval.c (vm_call0): fix prototype, the id parameter should be of
type ID, not VALUE * vm_insnhelper.c (check_match): the rb_funcall family of functions does not care about refinements. We need to use rb_method_entry_with_refinements instead to call === with refinements. Thanks to Jon Conley for reporting this bug. [ruby-core:57051] [Bug #8872] * test/ruby/test_refinement.rb: add test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c65e9bbff9
commit
66915c5077
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
Sat Sep 7 15:36:00 2013 Charlie Somerville <charliesome@ruby-lang.org>
|
||||||
|
|
||||||
|
* vm_eval.c (vm_call0): fix prototype, the id parameter should be of
|
||||||
|
type ID, not VALUE
|
||||||
|
|
||||||
|
* vm_insnhelper.c (check_match): the rb_funcall family of functions
|
||||||
|
does not care about refinements. We need to use
|
||||||
|
rb_method_entry_with_refinements instead to call === with
|
||||||
|
refinements. Thanks to Jon Conley for reporting this bug.
|
||||||
|
[ruby-core:57051] [Bug #8872]
|
||||||
|
|
||||||
|
* test/ruby/test_refinement.rb: add test
|
||||||
|
|
||||||
Sat Sep 7 13:49:40 2013 Kazuki Tsujimoto <kazuki@callcc.net>
|
Sat Sep 7 13:49:40 2013 Kazuki Tsujimoto <kazuki@callcc.net>
|
||||||
|
|
||||||
* variable.c (classname): the name of class that has
|
* variable.c (classname): the name of class that has
|
||||||
|
@ -961,6 +961,27 @@ class TestRefinement < Test::Unit::TestCase
|
|||||||
INPUT
|
INPUT
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_case_dispatch_is_aware_of_refinements
|
||||||
|
assert_in_out_err([], <<-RUBY, ["refinement used"], [])
|
||||||
|
module RefineSymbol
|
||||||
|
refine Symbol do
|
||||||
|
def ===(other)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
using RefineSymbol
|
||||||
|
|
||||||
|
case :a
|
||||||
|
when :b
|
||||||
|
puts "refinement used"
|
||||||
|
else
|
||||||
|
puts "refinement not used"
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def eval_using(mod, s)
|
def eval_using(mod, s)
|
||||||
|
@ -34,7 +34,7 @@ static VALUE send_internal(int argc, const VALUE *argv, VALUE recv, call_type sc
|
|||||||
static VALUE vm_call0_body(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv);
|
static VALUE vm_call0_body(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv);
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
vm_call0(rb_thread_t* th, VALUE recv, VALUE id, int argc, const VALUE *argv,
|
vm_call0(rb_thread_t* th, VALUE recv, ID id, int argc, const VALUE *argv,
|
||||||
const rb_method_entry_t *me, VALUE defined_class)
|
const rb_method_entry_t *me, VALUE defined_class)
|
||||||
{
|
{
|
||||||
rb_call_info_t ci_entry, *ci = &ci_entry;
|
rb_call_info_t ci_entry, *ci = &ci_entry;
|
||||||
|
@ -930,19 +930,24 @@ rb_equal_opt(VALUE obj1, VALUE obj2)
|
|||||||
return opt_eq_func(obj1, obj2, &ci);
|
return opt_eq_func(obj1, obj2, &ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
vm_call0(rb_thread_t*, VALUE, ID, int, const VALUE*, const rb_method_entry_t*, VALUE);
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
check_match(VALUE pattern, VALUE target, enum vm_check_match_type type)
|
check_match(VALUE pattern, VALUE target, enum vm_check_match_type type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case VM_CHECKMATCH_TYPE_WHEN:
|
case VM_CHECKMATCH_TYPE_WHEN:
|
||||||
return pattern;
|
return pattern;
|
||||||
case VM_CHECKMATCH_TYPE_CASE:
|
case VM_CHECKMATCH_TYPE_RESCUE:
|
||||||
return rb_funcall2(pattern, idEqq, 1, &target);
|
|
||||||
case VM_CHECKMATCH_TYPE_RESCUE: {
|
|
||||||
if (!rb_obj_is_kind_of(pattern, rb_cModule)) {
|
if (!rb_obj_is_kind_of(pattern, rb_cModule)) {
|
||||||
rb_raise(rb_eTypeError, "class or module required for rescue clause");
|
rb_raise(rb_eTypeError, "class or module required for rescue clause");
|
||||||
}
|
}
|
||||||
return RTEST(rb_funcall2(pattern, idEqq, 1, &target));
|
/* fall through */
|
||||||
|
case VM_CHECKMATCH_TYPE_CASE: {
|
||||||
|
VALUE defined_class;
|
||||||
|
rb_method_entry_t *me = rb_method_entry_with_refinements(CLASS_OF(pattern), idEqq, &defined_class);
|
||||||
|
return vm_call0(GET_THREAD(), pattern, idEqq, 1, &target, me, defined_class);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
rb_bug("check_match: unreachable");
|
rb_bug("check_match: unreachable");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user