Skip to content

Commit bdf2d79

Browse files
committed
Fix alias_module_function on JRuby
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
1 parent 1da7a2d commit bdf2d79

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎HISTORY.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Changes:
3030

3131
* `Hash#to_options` and `#to_options!` now exist. `facets/hash/to_options`
3232
only loaded `symbolize_keys` and never defined the aliases.
33+
* `Module#alias_module_function` now aliases the singleton method directly.
34+
On JRuby, the singleton method `module_function` created turned private
35+
when aliased again, which broke `URI.hash_to_query` under the test suite.
3336

3437
## 3.2.2 / 2026-06-15
3538

‎lib/core/facets/module/alias_module_function.rb‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class Module
2323
#
2424
def alias_module_function(new, old)
2525
alias_method(new, old)
26-
module_function(new)
26+
return module_function(new) unless singleton_class.method_defined?(old)
27+
# Alias the singleton method directly. On JRuby, a singleton method made
28+
# by #module_function turns private when it is itself aliased later.
29+
singleton_class.send(:alias_method, new, old)
2730
end
2831

2932
end

‎test/core/module/test_alias_module_function.rb‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ def x ; 33 ; end
1414
end
1515

1616
m.y.assert == 33
17+
m.private_method_defined?(:y).assert == true
18+
end
19+
20+
test "alias stays public when aliased again" do
21+
m = Module.new do
22+
module_function
23+
def x ; 33 ; end
24+
alias_module_function :y, :x
25+
end
1726

18-
# use send b/c private?
19-
#@m.send(:y).assert == 33
27+
m.singleton_class.send(:alias_method, :z, :y)
28+
m.z.assert == 33
2029
end
2130

2231
end

0 commit comments

Comments
 (0)