Repository navigation
kernel.c: give BasicObject the helpers defined? compiles to - #7838
Conversation
`defined?(@x)`, `defined?(X)`, `defined?(yield)` and the other forms compile to a call on self to a private helper such as __defined_ivar?. The helpers were Kernel's, so in a class that does not inherit Object (a BasicObject subclass) every `defined?` called method_missing, or raised NoMethodError, where CRuby answers. CRuby's delegate.rb recursed without end on it: SimpleDelegator#__getobj__ asks defined?(@obj), and its method_missing calls __getobj__. The helpers are now BasicObject's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X4cowTc1oGMNQfUma7zNdD
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
In a class that does not inherit from Object, every form of
defined?callsmethod_missing, or raisesNoMethodError:defined?(@x),defined?(X),defined?(A::B),defined?(@@x),defined?($x),defined?(yield),defined?(super)anddefined?(meth)compile to a call on self to a private helper (__defined_ivar?and the like). The helpers are Kernel's, and a BasicObject subclass has no Kernel.A class with a
method_missingthat forwards gets that call instead. CRuby's delegate.rb then recurses until the stack is exhausted:SimpleDelegator#__getobj__asksdefined?(@delegate_sd_obj), which goes toDelegator#method_missing, which calls__getobj__.Fix
The helpers move from Kernel to BasicObject, in a ROM table of their own. They stay private. Objects that inherit from Object find them as before, one step further up.
Test
test/t/basicobject.rbasks each form ofdefined?in a BasicObject subclass whosemethod_missingraises. The answers are the same as CRuby 4.1's.🤖 Generated with Claude Code
Summary by CodeRabbit
defined?now correctly reports definitions and missing names for objects that inherit directly fromBasicObject.super.