Skip to content

Commit 02f160a

Browse files
committed
Fix translating of splatted arguments to a call
* A single array argument is expected at runtime if there is any splat.
1 parent 5c3e58d commit 02f160a

File tree

3 files changed

+104
-79
lines changed

3 files changed

+104
-79
lines changed

spec/truffle/parsing/fixtures/method_calls/arguments/with_positional_argument_and_splat_operator.yaml

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,65 @@ ast: |
2323
notRuby2KeywordsHashProfile = false
2424
children:
2525
arguments = [
26-
RubyCallNode
26+
ArrayConcatNode
2727
attributes:
28-
descriptor = org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor@...
29-
dispatchConfig = PRIVATE
30-
emptyKeywordsProfile = false
3128
flags = 0
32-
isAttrAssign = false
33-
isSafeNavigation = false
34-
isSplatted = false
35-
isVCall = true
36-
lastArgIsNotHashProfile = false
37-
methodName = "bar"
38-
notEmptyKeywordsProfile = false
39-
notRuby2KeywordsHashProfile = false
4029
children:
41-
receiver =
42-
SelfNode
30+
children = [
31+
ArrayLiteralNode$UninitialisedArrayLiteralNode
4332
attributes:
4433
flags = 0
45-
SplatCastNodeGen
46-
attributes:
47-
conversionMethod = :to_a
48-
copy = true
49-
flags = 0
50-
nilBehavior = CONVERT
51-
children:
52-
childNode_ =
53-
RubyCallNode
34+
language = org.truffleruby.RubyLanguage@...
35+
children:
36+
values = [
37+
RubyCallNode
38+
attributes:
39+
descriptor = org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor@...
40+
dispatchConfig = PRIVATE
41+
emptyKeywordsProfile = false
42+
flags = 0
43+
isAttrAssign = false
44+
isSafeNavigation = false
45+
isSplatted = false
46+
isVCall = true
47+
lastArgIsNotHashProfile = false
48+
methodName = "bar"
49+
notEmptyKeywordsProfile = false
50+
notRuby2KeywordsHashProfile = false
51+
children:
52+
receiver =
53+
SelfNode
54+
attributes:
55+
flags = 0
56+
]
57+
SplatCastNodeGen
5458
attributes:
55-
descriptor = org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor@...
56-
dispatchConfig = PRIVATE
57-
emptyKeywordsProfile = false
59+
conversionMethod = :to_a
60+
copy = true
5861
flags = 0
59-
isAttrAssign = false
60-
isSafeNavigation = false
61-
isSplatted = false
62-
isVCall = true
63-
lastArgIsNotHashProfile = false
64-
methodName = "baz"
65-
notEmptyKeywordsProfile = false
66-
notRuby2KeywordsHashProfile = false
62+
nilBehavior = CONVERT
6763
children:
68-
receiver =
69-
SelfNode
64+
childNode_ =
65+
RubyCallNode
7066
attributes:
67+
descriptor = org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor@...
68+
dispatchConfig = PRIVATE
69+
emptyKeywordsProfile = false
7170
flags = 0
71+
isAttrAssign = false
72+
isSafeNavigation = false
73+
isSplatted = false
74+
isVCall = true
75+
lastArgIsNotHashProfile = false
76+
methodName = "baz"
77+
notEmptyKeywordsProfile = false
78+
notRuby2KeywordsHashProfile = false
79+
children:
80+
receiver =
81+
SelfNode
82+
attributes:
83+
flags = 0
84+
]
7285
]
7386
receiver =
7487
SelfNode

spec/truffle/parsing/fixtures/method_calls/arguments/with_splat_operator_and_positional_arguments.yaml

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,65 @@ ast: |
2626
notRuby2KeywordsHashProfile = false
2727
children:
2828
arguments = [
29-
SplatCastNodeGen
29+
ArrayConcatNode
3030
attributes:
31-
conversionMethod = :to_a
32-
copy = true
3331
flags = 0
34-
nilBehavior = CONVERT
3532
children:
36-
childNode_ =
37-
RubyCallNode
33+
children = [
34+
SplatCastNodeGen
3835
attributes:
39-
descriptor = org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor@...
40-
dispatchConfig = PRIVATE
41-
emptyKeywordsProfile = false
36+
conversionMethod = :to_a
37+
copy = true
4238
flags = 0
43-
isAttrAssign = false
44-
isSafeNavigation = false
45-
isSplatted = false
46-
isVCall = true
47-
lastArgIsNotHashProfile = false
48-
methodName = "bar"
49-
notEmptyKeywordsProfile = false
50-
notRuby2KeywordsHashProfile = false
39+
nilBehavior = CONVERT
5140
children:
52-
receiver =
53-
SelfNode
41+
childNode_ =
42+
RubyCallNode
5443
attributes:
44+
descriptor = org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor@...
45+
dispatchConfig = PRIVATE
46+
emptyKeywordsProfile = false
5547
flags = 0
56-
RubyCallNode
57-
attributes:
58-
descriptor = org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor@...
59-
dispatchConfig = PRIVATE
60-
emptyKeywordsProfile = false
61-
flags = 0
62-
isAttrAssign = false
63-
isSafeNavigation = false
64-
isSplatted = false
65-
isVCall = true
66-
lastArgIsNotHashProfile = false
67-
methodName = "baz"
68-
notEmptyKeywordsProfile = false
69-
notRuby2KeywordsHashProfile = false
70-
children:
71-
receiver =
72-
SelfNode
48+
isAttrAssign = false
49+
isSafeNavigation = false
50+
isSplatted = false
51+
isVCall = true
52+
lastArgIsNotHashProfile = false
53+
methodName = "bar"
54+
notEmptyKeywordsProfile = false
55+
notRuby2KeywordsHashProfile = false
56+
children:
57+
receiver =
58+
SelfNode
59+
attributes:
60+
flags = 0
61+
ArrayLiteralNode$UninitialisedArrayLiteralNode
7362
attributes:
7463
flags = 0
64+
language = org.truffleruby.RubyLanguage@...
65+
children:
66+
values = [
67+
RubyCallNode
68+
attributes:
69+
descriptor = org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor@...
70+
dispatchConfig = PRIVATE
71+
emptyKeywordsProfile = false
72+
flags = 0
73+
isAttrAssign = false
74+
isSafeNavigation = false
75+
isSplatted = false
76+
isVCall = true
77+
lastArgIsNotHashProfile = false
78+
methodName = "baz"
79+
notEmptyKeywordsProfile = false
80+
notRuby2KeywordsHashProfile = false
81+
children:
82+
receiver =
83+
SelfNode
84+
attributes:
85+
flags = 0
86+
]
87+
]
7588
]
7689
receiver =
7790
SelfNode

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,15 +657,14 @@ private ArgumentsAndBlockTranslation translateArgumentsAndBlock(Nodes.ArgumentsN
657657
arguments = argumentsNode.arguments;
658658
}
659659

660-
var translatedArguments = translate(arguments);
660+
boolean isSplatted = containYARPSplatNode(arguments);
661661
var argumentsDescriptor = getKeywordArgumentsDescriptor(arguments);
662662

663-
boolean isSplatted = false;
664-
for (var n : arguments) { // check if there is splat operator in the arguments list
665-
if (n instanceof Nodes.SplatNode) {
666-
isSplatted = true;
667-
break;
668-
}
663+
final RubyNode[] translatedArguments;
664+
if (isSplatted) {
665+
translatedArguments = new RubyNode[]{ translateExpressionsList(arguments) };
666+
} else {
667+
translatedArguments = translate(arguments);
669668
}
670669

671670
final RubyNode blockNode;

0 commit comments

Comments
 (0)