From: "sanjioh (Fabio Sangiovanni) via ruby-core" Date: 2025-01-29T15:17:59+00:00 Subject: [ruby-core:120830] [Ruby master Bug#21098] rb_alias: confusing error messages when the original method cannot be found and ZSUPER methods are involved Issue #21098 has been reported by sanjioh (Fabio Sangiovanni). ---------------------------------------- Bug #21098: rb_alias: confusing error messages when the original method cannot be found and ZSUPER methods are involved https://bugs.ruby-lang.org/issues/21098 * Author: sanjioh (Fabio Sangiovanni) * Status: Open * ruby -v: ruby 3.5.0dev (2025-01-29T13:19:04Z master 63b6323e04) +PRISM [x86_64-darwin24] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Hi all, I've noticed that the current implementation of `rb_alias` can raise `NameError` exceptions with confusing error messages when the original method cannot be found and ZSUPER methods are involved in the inheritance chain traversal. That's because `rb_print_undef` is invoked with the current value of `klass`, which is repeatedly reassigned whenever a ZSUPER method is encountered in the search, potentially referencing an ICLASS or FALSE. The following are 2 examples of this kind of behavior: ``` ruby module M private :class alias_method :xyz, :class # raises 'Module#alias_method': undefined method 'class' for class 'false' (NameError) end ``` ``` ruby module M private :class end module N prepend M alias_method :xyz, :class # raises 'Module#alias_method': undefined method 'class' for class '#' (NameError) end ``` The second example also triggers an assertion failure when they are enabled with `-DRUBY_DEBUG`: ``` ../vm_insnhelper.c:2192: Assertion Failed: rb_vm_search_method_slowpath:RB_TYPE_2_P(klass, RUBY_T_CLASS, RUBY_T_ICLASS): klass: T_MODULE ``` In the following PR I tried to fix the issue by invoking `rb_print_undef` with `target_klass` as argument, which holds the initial value of `klass`. https://github.com/ruby/ruby/pull/12665 The previous examples become as follows: ``` ruby module M private :class alias_method :xyz, :class # raises 'Module#alias_method': undefined method 'class' for module 'M' (NameError) end ``` ``` ruby module M private :class end module N prepend M alias_method :xyz, :class # raises 'Module#alias_method': undefined method 'class' for module 'N' (NameError) end ``` This is my first contribution to Ruby, so please let me know if I can improve it further. Cheers! -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/