Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8e631ca1d2f3
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ab440adf39e8
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Mar 27, 2018

  1. Range should raise TypeError if necessary method is not defined

    For more information, please see bug #14048.
    nomadium committed Mar 27, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    headius Charles Oliver Nutter
    Copy the full SHA
    ec02fe1 View commit details
  2. Merge pull request #5116 from nomadium/fix-range-ruby-2.5-should-rais…

    …e-type-error-if-necessary-method-is-not-defined
    
    Range should raise TypeError if necessary method is not defined
    headius authored Mar 27, 2018
    Copy the full SHA
    ab440ad View commit details
Showing with 21 additions and 2 deletions.
  1. +2 −2 core/src/main/java/org/jruby/RubyArray.java
  2. +16 −0 core/src/main/java/org/jruby/RubyRange.java
  3. +3 −0 core/src/main/java/org/jruby/runtime/JavaSites.java
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -1484,7 +1484,7 @@ private IRubyObject arefCommon(IRubyObject arg0) {
ThreadContext context = runtime.getCurrentContext();
ArraySites sites = sites(context);

if (RubyRange.isRangeLike(context, arg0, sites.respond_to_begin, sites.respond_to_end)) {
if (RubyRange.isRangeLike(context, arg0, sites.begin_checked, sites.end_checked, sites.exclude_end_checked)) {
RubyRange range = RubyRange.rangeFromRangeLike(context, arg0, sites.begin, sites.end, sites.exclude_end);

long[] beglen = range.begLen(realLength, 0);
@@ -1538,7 +1538,7 @@ public IRubyObject aset(IRubyObject arg0, IRubyObject arg1) {
ThreadContext context = getRuntime().getCurrentContext();
ArraySites sites = sites(context);

if (RubyRange.isRangeLike(context, arg0, sites.respond_to_begin, sites.respond_to_end)) {
if (RubyRange.isRangeLike(context, arg0, sites.begin_checked, sites.end_checked, sites.exclude_end_checked)) {
RubyRange range = RubyRange.rangeFromRangeLike(context, arg0, sites.begin, sites.end, sites.exclude_end);

long beg = range.begLen0(realLength);
16 changes: 16 additions & 0 deletions core/src/main/java/org/jruby/RubyRange.java
Original file line number Diff line number Diff line change
@@ -954,6 +954,22 @@ public static boolean isRangeLike(ThreadContext context, IRubyObject obj, Respon
respond_to_end.respondsTo(context, obj, obj);
}

/**
* Return true if the given object responds to "begin", "end" and "exclude_end?" methods.
*
* @param context current context
* @param obj possibly range-like object
* @param begin_checked checked site for begin
* @param end_checked checked site for end
* @param exclude_end_checked checked site for exclude_end?
* @return
*/
public static boolean isRangeLike(ThreadContext context, IRubyObject obj, JavaSites.CheckedSites begin_checked, JavaSites.CheckedSites end_checked, JavaSites.CheckedSites exclude_end_checked) {
return (obj.checkCallMethod(context, begin_checked) != null) &&
(obj.checkCallMethod(context, end_checked) != null) &&
(obj.checkCallMethod(context, exclude_end_checked) != null);
}

// MRI: rb_range_beg_len
public static IRubyObject rangeBeginLength(ThreadContext context, IRubyObject range, int len, int[] begLen, int err) {
JavaSites.RangeSites sites = sites(context);
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -91,6 +91,9 @@ public static class KernelSites {
}

public static class ArraySites {
public final CheckedSites begin_checked = new CheckedSites("begin");
public final CheckedSites end_checked = new CheckedSites("end");
public final CheckedSites exclude_end_checked = new CheckedSites("exclude_end?");
public final CheckedSites to_ary_checked = new CheckedSites("to_ary");
public final RespondToCallSite respond_to_to_ary = new RespondToCallSite("to_ary");
public final CallSite to_ary = new FunctionalCachingCallSite("to_ary");