Skip to content

Commit 338c2e8

Browse files
committed
Fix and specs for splatted index in optional element assignment.
1 parent 04118be commit 338c2e8

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

spec/ruby/language/optional_assignments_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def []=(k, v)
300300
(@b[:k] ||= 12).should == 12
301301
end
302302

303+
it 'correctly handles a splatted argument for the index' do
304+
(@b[*[:k]] ||= 12).should == 12
305+
end
306+
303307
it "evaluates the index precisely once" do
304308
ary = [:x, :y]
305309
@a[:x] = 15

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,9 +2541,15 @@ private ParseNode operation(
25412541
ArrayList<ValueFromNode> argValues,
25422542
String op,
25432543
ParseNode right) {
2544-
final ArrayParseNode readArguments = new ArrayParseNode(node.getPosition());
2545-
for (var arg : argValues) {
2546-
readArguments.add(arg.get(node.getPosition()));
2544+
ParseNode readArguments;
2545+
if (node.getArgsNode() instanceof ArrayParseNode) {
2546+
final ArrayParseNode readArgsArray = new ArrayParseNode(node.getPosition());
2547+
for (var arg : argValues) {
2548+
readArgsArray.add(arg.get(node.getPosition()));
2549+
}
2550+
readArguments = readArgsArray;
2551+
} else {
2552+
readArguments = argValues.get(0).get(node.getPosition());
25472553
}
25482554

25492555
final ParseNode read = new CallParseNode(

0 commit comments

Comments
 (0)