Skip to content

Attribute definition on singleton should call singleton_method_added#8070

Merged
headius merged 4 commits intojruby:masterfrom
headius:attr_calls_singleton_method_added
Jan 19, 2024
Merged

Attribute definition on singleton should call singleton_method_added#8070
headius merged 4 commits intojruby:masterfrom
headius:attr_calls_singleton_method_added

Conversation

@headius
Copy link
Member

@headius headius commented Jan 19, 2024

See Shopify/ruby-lsp#1263 for background on this.

When defining an attribute (attr, attr_reader, attr_writer, attr_accessor) on a metaclass or singleton object, we should be calling singleton_method_added. Instead, we were calling method_added.

The caused Shopify/ruby-lsp#1263 when an attr_reader in a metaclass body did not consume a Sorbet sig set up for it.

I've also factored out two other method hook cases in case they are needed other places in the future: method_undefined and method_removed.

We were only calling method_added, which does not match CRuby
behavior. This was the root cause of Shopify/ruby-lsp#1263.
These are only called in one place, but may be needed in the
future if they should be called for other logic that undefines or
removes methods.
If bound from a Java method, it almost certainly will have the
wrong signature for Ruby calls to it, leading to arity and other
errors when a singleton method or class method are defined on a
Java proxy type.
@headius headius merged commit 7eaf706 into jruby:master Jan 19, 2024
@headius headius deleted the attr_calls_singleton_method_added branch January 19, 2024 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant