From 9ca82710245f16f9cf1a0a223d6bdb7969520bb9 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Thu, 26 Oct 2023 00:31:24 -0500 Subject: [PATCH] Remove unnecessary cast of kwargs The intent here was to pass in what might be kwargs if the keyword flag was set, indicating that kwargs were being passed in. This assumption seems ok so I'm not sure why it doesn't hold. In any case, the cast here is unnecessary and the IRubyObject form will return null for non-RubyHashes. The code that triggered this does deal directly with kwargs, but as a kwrest, forwarding it through a block: https://github.com/rails/rails/blob/v7.1.1/activesupport/lib/active_support/testing/time_helpers.rb#L176-L183 This could indicate JRuby failing to pass along a keyword flag when forwarding kwrest. The additional changes here are: * Fall back on non-kwargs behavior if last arg turns out not to be a hash. * Remove a redundant reset of the `callInfo` that governs keyword- passing. --- core/src/main/java/org/jruby/RubyTime.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyTime.java b/core/src/main/java/org/jruby/RubyTime.java index 5a81b3a78b7b..a3c960c29b83 100644 --- a/core/src/main/java/org/jruby/RubyTime.java +++ b/core/src/main/java/org/jruby/RubyTime.java @@ -1715,16 +1715,21 @@ private IRubyObject initializeNow(ThreadContext context, IRubyObject zone) { public IRubyObject initialize(ThreadContext context, IRubyObject[] args) { boolean keywords = hasKeywords(context.resetCallInfo()); IRubyObject zone = null; - context.resetCallInfo(); IRubyObject nil = context.nil; int argc = args.length; if (keywords) { - IRubyObject in = ArgsUtil.extractKeywordArg(context, (RubyHash) args[argc - 1], "in"); - if (in != null && argc > 7) { - throw context.runtime.newArgumentError("timezone argument given as positional and keyword arguments"); + IRubyObject in = ArgsUtil.extractKeywordArg(context, args[argc - 1], "in"); + if (in != null) { + if (argc > 7) { + throw context.runtime.newArgumentError("timezone argument given as positional and keyword arguments"); + } + zone = in; + } else { + if (argc > 6) { + zone = args[6]; + } } - zone = in; } else if (argc > 6) { zone = args[6]; }