Repository navigation
Fix alias_module_function on JRuby - #327
Merged
Merged
Conversation
On JRuby 10.1, a singleton method created by module_function(name) turns private when it is aliased again. Lemon aliases each method under test to wrap and then restore it, so after the URI.hash_to_query test ran, Hash#to_uri failed with "private method 'hash_to_query' called for module URI". This was the only failing test in the JRuby CI job. alias_module_function now aliases the singleton method directly, which stays public on JRuby. If the old method isn't a module function, it falls back to module_function as before. Adds a test that re-aliases the new singleton method; it fails on JRuby without this fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the only failing test in the JRuby CI job (
test/standard/test_uri.rb:private method 'hash_to_query' called for module URI), which has been red onmainsince at least #325.Cause
URI.hash_to_queryis defined withalias_module_function :hash_to_query, :query, which callsalias_methodand thenmodule_function(new).module_function(name)creates is public, but it turns private as soon as it's aliased again. CRuby keeps it public.URI.hash_to_querytest ran, the method was private, and the laterHash#to_uritest failed.Normal callers don't hit this unless they re-alias the method, but anything that wraps methods the way Lemon does will.
Fix
alias_module_functionnow aliases the singleton method directly:That matches the documented contract ("alias a module function so the alias is also a module function"), and the result stays public on JRuby. If
oldisn't a module function, it falls back tomodule_function(new)exactly as before.Testing
I reproduced this locally with JRuby 10.1.2.0, the version CI uses.
🤖 Generated with Claude Code
https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW
Generated by Claude Code