Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Object#instance_exec will raise a TypeError when defining/alias metho…

…ds on numerics.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

assert_raise(TypeError){ 1.instance_exec { def foo; end } }
assert_raise(TypeError){ 1.instance_exec { alias :foo :to_s} }

puts :ok
}}}
  • Loading branch information...
commit 351ebd767c260a85e9896f000629fc9df3397f45 1 parent 01965bc
@Watson1978 Watson1978 authored
View
2  spec/frozen/tags/macruby/core/object/instance_exec_tags.txt
@@ -1,3 +1 @@
fails:Object#instance_exec sets class variables in the receiver
-fails:Object#instance_exec raises a TypeError when defining methods on an immediate
-fails:Object#instance_exec raises a TypeError when defining methods on numerics
View
6 vm.cpp
@@ -1543,6 +1543,9 @@ rb_vm_alias2(VALUE outer, VALUE name, VALUE def, unsigned char dynamic_class)
outer = (VALUE)k;
}
}
+ if (NIL_P(outer)) {
+ rb_raise(rb_eTypeError, "no class to make alias");
+ }
// Given arguments should always be symbols (compiled as such).
assert(TYPE(name) == T_SYMBOL);
@@ -2062,6 +2065,9 @@ prepare_method(Class klass, bool dynamic_class, SEL sel, void *data,
}
}
}
+ if (NIL_P(klass)) {
+ rb_raise(rb_eTypeError, "no class/module to add method");
+ }
const long v = RCLASS_VERSION(klass);
if (v & RCLASS_SCOPE_PRIVATE) {
View
2  vm_eval.c
@@ -561,7 +561,7 @@ rb_obj_instance_exec(VALUE self, SEL sel, int argc, VALUE *argv)
VALUE klass;
if (SPECIAL_CONST_P(self)) {
- klass = 0;
+ klass = Qnil;
}
else {
klass = rb_singleton_class(self);
Please sign in to comment.
Something went wrong with that request. Please try again.