Skip to content

Commit 94cfbac

Browse files
committed
Updated semantics in spec and RangeNodes.java
1 parent 4da431a commit 94cfbac

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

spec/ruby/language/range_spec.rb

+12-8
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,25 @@
1919
it "is frozen" do
2020
(42..).should.frozen?
2121
end
22+
end
23+
24+
ruby_version_is "2.7" do
25+
it "creates beginless ranges" do
26+
eval("(..1)").should == Range.new(nil, 1)
27+
eval("(...1)").should == Range.new(nil, 1, true)
28+
end
29+
end
30+
end
2231

32+
describe "Object Ranges" do
33+
ruby_version_is "3.0" do
2334
it "is not frozen if it is a subclass of Range" do
24-
change_range = Class.new(Range)
35+
change_range = Class.new(Range).new(1, 2)
2536
change_range.should_not.frozen?
2637
end
2738

2839
it "is not frozen if it is created through allocate" do
2940
Range.allocate.should_not.frozen?
3041
end
3142
end
32-
33-
ruby_version_is "2.7" do
34-
it "creates beginless ranges" do
35-
eval("(..1)").should == Range.new(nil, 1)
36-
eval("(...1)").should == Range.new(nil, 1, true)
37-
end
38-
end
3943
end

src/main/java/org/truffleruby/core/range/RangeNodes.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -548,18 +548,18 @@ protected RubyLongRange longRange(RubyClass rubyClass, long begin, long end, boo
548548
return range;
549549
}
550550

551-
@Specialization(guards = { "nonStandardClass || (!isImplicitLong(begin) || !isImplicitLong(end))" })
551+
@Specialization(guards = { "!standardClass || (!isImplicitLong(begin) || !isImplicitLong(end))" })
552552
protected RubyObjectRange objectRange(RubyClass rubyClass, Object begin, Object end, boolean excludeEnd,
553553
@Cached DispatchNode compare,
554-
@Bind("rubyClass != getRangeClass()") boolean nonStandardClass) {
554+
@Bind("rubyClass == getRangeClass()") boolean standardClass) {
555555

556556
if (compare.call(begin, "<=>", end) == nil && end != nil && begin != nil) {
557557
throw new RaiseException(getContext(), coreExceptions().argumentError("bad value for range", this));
558558
}
559559

560560
final Shape shape = getLanguage().objectRangeShape;
561561
final RubyObjectRange range = new RubyObjectRange(rubyClass, shape, excludeEnd, begin, end,
562-
!nonStandardClass);
562+
standardClass);
563563
AllocationTracing.trace(range, this);
564564
return range;
565565
}

0 commit comments

Comments
 (0)