diff --git a/core/src/main/java/org/jruby/RubyFile.java b/core/src/main/java/org/jruby/RubyFile.java index abc1527b79d..2315103f526 100644 --- a/core/src/main/java/org/jruby/RubyFile.java +++ b/core/src/main/java/org/jruby/RubyFile.java @@ -45,6 +45,7 @@ import org.jruby.anno.JRubyClass; import org.jruby.anno.JRubyMethod; import org.jruby.exceptions.NotImplementedError; +import org.jruby.ir.runtime.IRRuntimeHelpers; import org.jruby.runtime.*; import org.jruby.runtime.JavaSites.FileSites; import org.jruby.runtime.builtin.IRubyObject; @@ -344,9 +345,11 @@ public IRubyObject flock(ThreadContext context, IRubyObject operation) { // rb_file_initialize @JRubyMethod(name = "initialize", required = 1, optional = 3, checkArity = false, visibility = PRIVATE, keywords = true) public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) { - boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context)); + // capture callInfo for delegating to IO#initialize + int callInfo = context.callInfo; + IRubyObject keywords = IRRuntimeHelpers.receiveKeywords(context, args, false, true, false); // Mild hack. We want to arity-mismatch if extra arg is not really a kwarg but not if it is one. - int maxArgs = keywords ? 4 : 3; + int maxArgs = keywords instanceof RubyHash ? 4 : 3; int argc = Arity.checkArgumentCount(context, args, 1, maxArgs); if (openFile != null) throw context.runtime.newRuntimeError("reinitializing File"); @@ -354,6 +357,8 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block b if (argc > 0 && argc <= 3) { IRubyObject fd = TypeConverter.convertToTypeWithCheck(context, args[0], context.runtime.getFixnum(), sites(context).to_int_checked); if (!fd.isNil()) { + // restore callInfo for delegated call to IO#initialize + IRRuntimeHelpers.setCallInfo(context, callInfo); if (argc == 1) { return super.initialize(context, fd, block); } else if (argc == 2) { diff --git a/core/src/main/java/org/jruby/RubyIO.java b/core/src/main/java/org/jruby/RubyIO.java index bca1df6a3dc..23af858c3ee 100644 --- a/core/src/main/java/org/jruby/RubyIO.java +++ b/core/src/main/java/org/jruby/RubyIO.java @@ -4229,7 +4229,7 @@ public static IRubyObject binread(ThreadContext context, IRubyObject recv, IRuby // Enebo: annotation processing forced me to do pangea method here... @JRubyMethod(name = "read", meta = true, required = 1, optional = 3, checkArity = false, keywords = true) public static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { - boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context)); + IRubyObject keywords = IRRuntimeHelpers.receiveKeywords(context, args, false, true, false); int argc = Arity.checkArgumentCount(context, args, 1, 4); Ruby runtime = context.runtime; @@ -4239,20 +4239,20 @@ public static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObj { // rb_scan_args logic, basically if (argc > 3) { - if (!keywords) throw runtime.newArgumentError(args.length, 1, 4); - options = (RubyHash) args[3]; + if (!(keywords instanceof RubyHash)) throw runtime.newArgumentError(args.length, 1, 4); + options = args[3]; offset = args[2]; length = args[1]; } else if (argc > 2) { - if (args[2] instanceof RubyHash) { - options = (RubyHash) args[2]; + if (keywords instanceof RubyHash) { + options = keywords; } else { offset = args[2]; } length = args[1]; } else if (argc > 1) { - if (args[1] instanceof RubyHash) { - options = (RubyHash) args[1]; + if (keywords instanceof RubyHash) { + options = keywords; } else { length = args[1]; }