Skip to content

Commit

Permalink
Ensure singleton_method_added is called for attr on singleton
Browse files Browse the repository at this point in the history
We were only calling method_added, which does not match CRuby
behavior. This was the root cause of Shopify/ruby-lsp#1263.
  • Loading branch information
headius committed Jan 19, 2024
1 parent d56f620 commit 1008344
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2289,11 +2289,19 @@ private void addAccessor(ThreadContext context, RubySymbol identifier, Visibilit
final String variableName = identifier.asInstanceVariable().idString();
if (readable) {
addMethod(internedIdentifier, new AttrReaderMethod(methodLocation, visibility, variableName));
callMethod(context, "method_added", identifier);
methodAdded(context, identifier);
}
if (writeable) {
identifier = identifier.asWriter();
addMethod(identifier.idString(), new AttrWriterMethod(methodLocation, visibility, variableName));
methodAdded(context, identifier);
}
}

protected void methodAdded(ThreadContext context, RubySymbol identifier) {
if (isSingleton()) {
((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", identifier);
} else {
callMethod(context, "method_added", identifier);
}
}
Expand Down Expand Up @@ -3491,7 +3499,7 @@ public IRubyObject _module_function(ThreadContext context, IRubyObject[] args) {
newMethod.setImplementationClass(getSingletonClass());
newMethod.setVisibility(PUBLIC);
getSingletonClass().addMethod(name.idString(), newMethod);
callMethod(context, "singleton_method_added", name);
getSingletonClass().methodAdded(context, name);
}
}

Expand Down Expand Up @@ -3619,11 +3627,7 @@ public IRubyObject aliasMethod(ThreadContext context, IRubyObject newId, IRubyOb

defineAlias(newSym.idString(), oldSym.idString());

if (isSingleton()) {
((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", newSym);
} else {
callMethod(context, "method_added", newSym);
}
methodAdded(context, newSym);

return newSym;
}
Expand Down

0 comments on commit 1008344

Please sign in to comment.