rb_alias: improve "undefined method" error message by invoking

`rb_print_undef` with `target_klass` as argument.
This commit is contained in:
Fabio Sangiovanni 2025-01-29 14:57:58 +01:00 committed by Nobuyoshi Nakada
parent 5032791330
commit f0dc9dcdc7
Notes: git 2025-01-30 15:21:04 +00:00
2 changed files with 14 additions and 1 deletions

View File

@ -328,4 +328,17 @@ class TestAlias < Test::Unit::TestCase
}
end;
end
def test_undef_method_error_message_with_zsuper_method
modules = [
Module.new { private :class },
Module.new { prepend Module.new { private :class } },
]
message = "undefined method 'class' for module '%s'"
modules.each do |mod|
assert_raise_with_message(NameError, message % mod) do
mod.alias_method :xyz, :class
end
end
end
end

View File

@ -2311,7 +2311,7 @@ rb_alias(VALUE klass, ID alias_name, ID original_name)
if ((!RB_TYPE_P(klass, T_MODULE)) ||
(orig_me = search_method(rb_cObject, original_name, &defined_class),
UNDEFINED_METHOD_ENTRY_P(orig_me))) {
rb_print_undef(klass, original_name, METHOD_VISI_UNDEF);
rb_print_undef(target_klass, original_name, METHOD_VISI_UNDEF);
}
}