Skip to content

Commit

Permalink
Fix TestRange#test_reverse_each_for_single_point_range MRI test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Jan 16, 2025
1 parent f4f9bf8 commit 848ac54
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 67 deletions.
64 changes: 0 additions & 64 deletions src/main/java/org/truffleruby/core/range/RangeNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,70 +418,6 @@ public RubyNode cloneUninitialized() {
}
}

@CoreMethod(names = "reverse_each", needsBlock = true, enumeratorSize = "size")
public abstract static class ReverseEachNode extends CoreMethodArrayArgumentsNode {

@Child private DispatchNode reverseEachInternalCall;

@Specialization
RubyIntRange reverseEachInt(RubyIntRange range, RubyProc block,
@Cached @Shared InlinedConditionProfile excludedEndProfile,
@Cached @Exclusive InlinedLoopConditionProfile loopProfile,
@Cached @Shared CallBlockNode yieldNode) {
final int end;
if (excludedEndProfile.profile(this, range.excludedEnd)) {
end = range.end - 1;
} else {
end = range.end;
}

int n = end;
try {
for (; loopProfile.inject(this, n >= range.begin); n--) {
yieldNode.yield(this, block, n);
}
} finally {
profileAndReportLoopCount(this, loopProfile, end - range.begin + 1);
}

return range;
}

@Specialization
RubyLongRange reverseEachLong(RubyLongRange range, RubyProc block,
@Cached @Shared InlinedConditionProfile excludedEndProfile,
@Cached @Exclusive InlinedLoopConditionProfile loopProfile,
@Cached @Shared CallBlockNode yieldNode) {
final long end;
if (excludedEndProfile.profile(this, range.excludedEnd)) {
end = range.end - 1;
} else {
end = range.end;
}

long n = end;
try {
for (; loopProfile.inject(this, n >= range.begin); n--) {
yieldNode.yield(this, block, n);
}
} finally {
profileAndReportLoopCount(this, loopProfile, end - range.begin + 1);
}

return range;
}

@Specialization
Object reverseEachObject(RubyObjectRange range, RubyProc block) {
if (reverseEachInternalCall == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
reverseEachInternalCall = insert(DispatchNode.create());
}

return reverseEachInternalCall.callWithBlock(range, "reverse_each_internal", block);
}
}

@GenerateCached(false)
@GenerateInline
public abstract static class NewRangeNode extends RubyBaseNode {
Expand Down
4 changes: 2 additions & 2 deletions src/main/ruby/truffleruby/core/range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ def %(n)
Truffle::RangeOperations.step_no_block(self, n)
end

private def reverse_each_internal(&block)
return to_enum { size } unless block_given?
def reverse_each(&block)
return to_enum(:reverse_each) { size } unless block_given?

if Primitive.nil?(self.end)
raise TypeError, "can't iterate from NilClass"
Expand Down
1 change: 0 additions & 1 deletion test/mri/excludes/TestRange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
exclude :test_reverse_each_for_beginless_range, "TypeError: can't iterate from NilClass"
exclude :test_reverse_each_for_empty_range, "RangeError: long too big to convert into `int'"
exclude :test_reverse_each_for_endless_range, "[TypeError] exception expected, not #<RangeError: cannot convert endless range to an array>."
exclude :test_reverse_each_for_single_point_range, "<no message> (java.lang.NegativeArraySizeException)"
exclude :test_size, "<3> expected but was <(31/10)>."
exclude :test_step, "ArgumentError expected but nothing was raised."
exclude :test_step_with_succ, "NoMethodError: undefined method `i' for nil:NilClass"

0 comments on commit 848ac54

Please sign in to comment.