* [ruby-core:120830] [Ruby master Bug#21098] rb_alias: confusing error messages when the original method cannot be found and ZSUPER methods are involved
@ 2025-01-29 15:17 sanjioh (Fabio Sangiovanni) via ruby-core
2025-01-30 17:27 ` [ruby-core:120847] " alanwu (Alan Wu) via ruby-core
0 siblings, 1 reply; 2+ messages in thread
From: sanjioh (Fabio Sangiovanni) via ruby-core @ 2025-01-29 15:17 UTC (permalink / raw)
To: ruby-core; +Cc: sanjioh (Fabio Sangiovanni)
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 '#<N:0x0000000124ba7f00>' (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/
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:120847] [Ruby master Bug#21098] rb_alias: confusing error messages when the original method cannot be found and ZSUPER methods are involved
2025-01-29 15:17 [ruby-core:120830] [Ruby master Bug#21098] rb_alias: confusing error messages when the original method cannot be found and ZSUPER methods are involved sanjioh (Fabio Sangiovanni) via ruby-core
@ 2025-01-30 17:27 ` alanwu (Alan Wu) via ruby-core
0 siblings, 0 replies; 2+ messages in thread
From: alanwu (Alan Wu) via ruby-core @ 2025-01-30 17:27 UTC (permalink / raw)
To: ruby-core; +Cc: alanwu (Alan Wu)
Issue #21098 has been updated by alanwu (Alan Wu).
Status changed from Open to Closed
https://github.com/ruby/ruby/pull/12665 landed in commit:f0dc9dcdc7a3b15b3192b1503a3c3d9eec3ada06.
----------------------------------------
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#change-111723
* Author: sanjioh (Fabio Sangiovanni)
* Status: Closed
* 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 '#<N:0x0000000124ba7f00>' (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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-30 17:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-29 15:17 [ruby-core:120830] [Ruby master Bug#21098] rb_alias: confusing error messages when the original method cannot be found and ZSUPER methods are involved sanjioh (Fabio Sangiovanni) via ruby-core
2025-01-30 17:27 ` [ruby-core:120847] " alanwu (Alan Wu) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).