Skip to content

Commit 63167f1

Browse files
committed
Remove incorrect check for the first optional argument
* Fixes #2302 (cherry picked from commit b64bf06)
1 parent 4a3bb93 commit 63167f1

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Bug fixes:
2323
* Fix control flow bug when assigning constants using ||= (#1489).
2424
* Fix `Kernel#raise` argument handling for hashes (#2298).
2525
* Set errinfo when `rb_protect` captures a Ruby exception (#2245).
26+
* Fixed handling of multiple optional arguments and keywords when passed a positional `Hash` (#2302).
2627

2728
Compatibility:
2829

src/main/java/org/truffleruby/parser/LoadArgumentsTranslator.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ private enum State {
105105
private int index;
106106
private int indexFromEnd = 1;
107107
private State state;
108-
private boolean firstOpt = false;
109108

110109
public LoadArgumentsTranslator(
111110
Node currentNode,
@@ -180,7 +179,6 @@ public RubyNode translate() {
180179
index = argsNode.getPreCount();
181180
final int optArgIndex = argsNode.getOptArgIndex();
182181
for (int i = 0; i < optArgCount; i++) {
183-
firstOpt = i == 0;
184182
sequence.add(args[optArgIndex + i].accept(this));
185183
++index;
186184
}
@@ -349,8 +347,7 @@ public RubyNode visitRestArgNode(RestArgParseNode node) {
349347
if (useArray()) {
350348
readNode = ArraySliceNodeGen.create(from, to, loadArray(sourceSection));
351349
} else {
352-
boolean considerRejectedKWArgs = considerRejectedKWArgs();
353-
readNode = new ReadRestArgumentNode(from, -to, hasKeywordArguments, considerRejectedKWArgs, required);
350+
readNode = new ReadRestArgumentNode(from, -to, hasKeywordArguments, considerRejectedKWArgs(), required);
354351
}
355352

356353
final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(node.getName());
@@ -440,11 +437,10 @@ private RubyNode translateLocalAssignment(SourceIndexLength sourcePosition, Stri
440437
minimum += 1;
441438
}
442439

443-
final boolean considerRejectedKWArgs = firstOpt && considerRejectedKWArgs();
444440
readNode = new ReadOptionalArgumentNode(
445441
index,
446442
minimum,
447-
considerRejectedKWArgs,
443+
considerRejectedKWArgs(),
448444
argsNode.hasKwargs(),
449445
required,
450446
defaultValue);

0 commit comments

Comments
 (0)