Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compatibility] Enable tests for Module#used_refinements #3097

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/truffleruby.next-specs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ spec/ruby/core/string/byterindex_spec.rb
spec/ruby/core/queue/deq_spec.rb
spec/ruby/core/queue/pop_spec.rb
spec/ruby/core/queue/shift_spec.rb

spec/ruby/core/module/used_refinements_spec.rb
2 changes: 1 addition & 1 deletion src/main/java/org/truffleruby/core/module/ModuleNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,7 @@ public abstract static class UsedRefinementsNode extends CoreMethodArrayArgument
protected RubyArray usedRefinements() {
final Frame frame = getContext().getCallStack().getCallerFrame(FrameAccess.READ_ONLY);
final DeclarationContext declarationContext = RubyArguments.getDeclarationContext(frame);
final Set<RubyModule> refinements = new HashSet<>();
final List<RubyModule> refinements = new ArrayList<>();
for (RubyModule[] refinementModules : declarationContext.getRefinements().values()) {
for (RubyModule refinementModule : refinementModules) {
refinements.add(refinementModule);
Expand Down
17 changes: 17 additions & 0 deletions test/mri/tests/ruby/test_refinement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1791,13 +1791,17 @@ module RefA
refine Object do
def in_ref_a
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RefA.const_set(:REF, self)
end
end

module RefB
refine Object do
def in_ref_b
end

RefB.const_set(:REF, self)
end
end

Expand All @@ -1807,23 +1811,28 @@ module RefC
refine Object do
def in_ref_c
end

RefC.const_set(:REF, self)
end
end

module Foo
using RefB
USED_MODS = Module.used_modules
USED_REFS = Module.used_refinements
end

module Bar
using RefC
USED_MODS = Module.used_modules
USED_REFS = Module.used_refinements
end

module Combined
using RefA
using RefB
USED_MODS = Module.used_modules
USED_REFS = Module.used_refinements
end
end

Expand All @@ -1835,6 +1844,14 @@ def test_used_modules
assert_equal [ref::RefB, ref::RefA], ref::Combined::USED_MODS
end

def test_used_refinements
ref = VisibleRefinements
assert_equal [], Module.used_refinements
assert_equal [ref::RefB::REF], ref::Foo::USED_REFS
assert_equal [ref::RefC::REF], ref::Bar::USED_REFS
assert_equal [ref::RefB::REF, ref::RefA::REF], ref::Combined::USED_REFS
end

def test_warn_setconst_in_refinmenet
bug10103 = '[ruby-core:64143] [Bug #10103]'
warnings = [
Expand Down