From cc89d494a6c552743f95e3f079eb0e2c3d97951b Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 3 Jul 2019 16:03:30 -0700 Subject: [PATCH] Use more explicit error message if wrong type when reopening class/module Include the current class of the object in the error message. Fixes [Bug #11460] --- test/ruby/test_class.rb | 4 ++-- test/ruby/test_module.rb | 4 ++-- vm_insnhelper.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 93278a918f..7527a92960 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -588,12 +588,12 @@ def test_namescope_error_message def test_redefinition_mismatch m = Module.new m.module_eval "A = 1" - assert_raise_with_message(TypeError, /is not a class/) { + assert_raise_with_message(TypeError, /is not a class, it is a Integer/) { m.module_eval "class A; end" } n = "M\u{1f5ff}" m.module_eval "#{n} = 42" - assert_raise_with_message(TypeError, "#{n} is not a class") { + assert_raise_with_message(TypeError, "#{n} is not a class, it is a Integer") { m.module_eval "class #{n}; end" } diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 604edf5f59..a60d48d20e 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -2340,12 +2340,12 @@ def test_define_method_with_unbound_method def test_redefinition_mismatch m = Module.new m.module_eval "A = 1" - assert_raise_with_message(TypeError, /is not a module/) { + assert_raise_with_message(TypeError, /is not a module, it is a Integer/) { m.module_eval "module A; end" } n = "M\u{1f5ff}" m.module_eval "#{n} = 42" - assert_raise_with_message(TypeError, "#{n} is not a module") { + assert_raise_with_message(TypeError, "#{n} is not a module, it is a Integer") { m.module_eval "module #{n}; end" } diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 93b1ebfe7a..9e4c242e2b 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -3396,7 +3396,7 @@ static VALUE vm_check_if_class(ID id, rb_num_t flags, VALUE super, VALUE klass) { if (!RB_TYPE_P(klass, T_CLASS)) { - rb_raise(rb_eTypeError, "%"PRIsVALUE" is not a class", rb_id2str(id)); + rb_raise(rb_eTypeError, "%"PRIsVALUE" is not a class, it is a %s", rb_id2str(id), rb_builtin_class_name(klass)); } else if (VM_DEFINECLASS_HAS_SUPERCLASS_P(flags)) { VALUE tmp = rb_class_real(RCLASS_SUPER(klass)); @@ -3419,7 +3419,7 @@ static VALUE vm_check_if_module(ID id, VALUE mod) { if (!RB_TYPE_P(mod, T_MODULE)) { - rb_raise(rb_eTypeError, "%"PRIsVALUE" is not a module", rb_id2str(id)); + rb_raise(rb_eTypeError, "%"PRIsVALUE" is not a module, it is a %s", rb_id2str(id), rb_builtin_class_name(mod)); } else { return mod; -- 2.21.0