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: d9ab72f4483a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9295b2f1394b
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Jun 29, 2015

  1. anonkeyrest not covered in ArgumentType.valueOf

    ... this ended as NPE with MethodArgs2 (fixes #3086)
    kares committed Jun 29, 2015
    Copy the full SHA
    dbd85dd View commit details
  2. trying to cover a test-case for #3086

    ... likely need to be warmed as these pass fine (without previous fix)
    kares committed Jun 29, 2015
    Copy the full SHA
    df595e2 View commit details
  3. Copy the full SHA
    b6977f3 View commit details
  4. add mixed parameters asserts

    kares committed Jun 29, 2015
    Copy the full SHA
    9295b2f View commit details
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/runtime/ArgumentDescriptor.java
Original file line number Diff line number Diff line change
@@ -33,11 +33,10 @@ public String toPrefixForm() {
return type.renderPrefixForm(name);
}

public RubyArray toArrayForm(Ruby runtime, boolean isLambda) {
if (type == ArgumentType.req && !isLambda) {
public final RubyArray toArrayForm(Ruby runtime, boolean isLambda) {
if ( type == ArgumentType.req && ! isLambda ) {
return ArgumentType.opt.toArrayForm(runtime, name);
} else {
return type.toArrayForm(runtime, name);
}
return type.toArrayForm(runtime, name);
}
}
40 changes: 21 additions & 19 deletions core/src/main/java/org/jruby/runtime/ArgumentType.java
Original file line number Diff line number Diff line change
@@ -7,23 +7,24 @@
* Created by headius on 5/8/15.
*/
public enum ArgumentType {
key("key", "k", false),
keyreq("keyreq", "K", false),
keyrest("keyrest", "e", false),
block("block", "b", false),
opt("opt", "o", false),
rest("rest", "r", false),
req("req", "q", false),
anonreq("req", "n", true),
anonopt("opt", "O", true),
anonrest("rest", "R", true),
anonkeyrest("keyrest", "N", true);

public static final String ANONOPT = anonopt.prefix;
public static final String ANONREST = anonrest.prefix;
public static final String REQ = req.prefix;

ArgumentType(String symbolicName, String prefix, boolean anonymous) {

key("key", 'k', false),
keyreq("keyreq", 'K', false),
keyrest("keyrest", 'e', false),
block("block", 'b', false),
opt("opt", 'o', false),
rest("rest", 'r', false),
req("req", 'q', false),
anonreq("req", 'n', true),
anonopt("opt", 'O', true),
anonrest("rest", 'R', true),
anonkeyrest("keyrest", 'N', true);

public static final String ANONOPT = Character.toString( anonopt.prefix );
public static final String ANONREST = Character.toString( anonrest.prefix );
public static final String REQ = Character.toString( req.prefix );

private ArgumentType(String symbolicName, char prefix, boolean anonymous) {
this.symbolicName = symbolicName;
this.prefix = prefix;
this.anonymous = anonymous;
@@ -38,9 +39,10 @@ public static ArgumentType valueOf(char prefix) {
case 'o': return opt;
case 'r': return rest;
case 'q': return req;
case 'R': return anonrest;
case 'n': return anonreq;
case 'O': return anonopt;
case 'R': return anonrest;
case 'N': return anonkeyrest;
default: return null;
}
}
@@ -54,6 +56,6 @@ public RubyArray toArrayForm(Ruby runtime, String name) {
}

public final String symbolicName;
public final String prefix;
private final char prefix;
public final boolean anonymous;
}
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@

import jnr.constants.platform.Errno;
import org.jruby.*;
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.ArgsNode;
import org.jruby.ast.ArgumentNode;
import org.jruby.ast.DAsgnNode;
@@ -2508,11 +2507,13 @@ public static ArgumentDescriptor[] parameterListToArgumentDescriptors(String[] p
public static RubyArray argumentDescriptorsToParameters(Ruby runtime, ArgumentDescriptor[] argsDesc, boolean isLambda) {
if (argsDesc == null) Thread.dumpStack();

RubyArray parms = RubyArray.newArray(runtime, argsDesc.length);
final RubyArray params = RubyArray.newArray(runtime, argsDesc.length);

for (ArgumentDescriptor param : argsDesc) parms.add(param.toArrayForm(runtime, isLambda));
for (ArgumentDescriptor param : argsDesc) {
params.append( param.toArrayForm(runtime, isLambda) );
}

return parms;
return params;
}

public static ArgumentDescriptor[] methodToArgumentDescriptors(DynamicMethod method) {
40 changes: 39 additions & 1 deletion test/jruby/test_method.rb
Original file line number Diff line number Diff line change
@@ -11,8 +11,46 @@ def test_jruby_3491
def test_function_break
obj = Object.new
def obj.broken_method
break
break # TODO this is a SyntaxError on MRI 2.2.2
end
assert_raise(LocalJumpError){obj.broken_method}
end

module Methods
def self.req2(a1, a2); a1 || a2 end
def self.opt1(a1, a2 = {}); a1 if a2 end
def self.key(foo: 1, bar: 2) foo || bar end
def self.keyrest(foo: 1, **bar) bar end
def self.key_block(foo: 1, &bar) bar end
def self.anonkeyrest(**) end
def self.resta(*a) a end
def self.mix(a1, *a2, a3, foo: 1, **bar) end
end

def test_parameters
assert_equal [[:req, :a1], [:req, :a2]], Methods.method(:req2).parameters
assert_equal [[:req, :a1], [:opt, :a2]], Methods.method(:opt1).parameters

assert_equal [[:key, :foo], [:key, :bar]], Methods.method(:key).parameters
assert_equal [[:key, :foo], [:keyrest, :bar]], Methods.method(:keyrest).parameters
assert_equal [[:key, :foo], [:block, :bar]], Methods.method(:key_block).parameters
assert_equal [[:keyrest]], Methods.method(:anonkeyrest).parameters

assert_equal [[:rest, :a]], Methods.method(:resta).parameters
assert_equal [[ :rest ]], String.method(:new).parameters

assert_equal [[:req, :a1], [:rest, :a2], [:req, :a3], [:key, :foo], [:keyrest, :bar]], Methods.method(:mix).parameters

assert_equal [[:req, :a1]], lambda { |a1| }.parameters
assert_equal [[:req, :a1], [:opt, :a2]], lambda { |a1, a2 = {}| }.parameters

assert_equal [[:key, :foo], [:key, :bar]], lambda { |foo: 1, bar: 2| }.parameters
assert_equal [[:key, :foo], [:keyrest, :bar]], lambda { |foo: 1, **bar| }.parameters
assert_equal [[:keyrest]], lambda { |**| }.parameters

assert_equal [[:rest]], lambda { |*| }.parameters

assert_equal [[:req, :a1], [:rest, :a2], [:req, :a3], [:key, :foo], [:keyrest, :bar]], lambda { |a1, *a2, a3, foo: 1, **bar| }.parameters
end

end