Skip to content

Commit 5685bca

Browse files
committed
Handle methods with a null ParametersNode
1 parent 4b63a14 commit 5685bca

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ public class YARPTranslator extends AbstractNodeVisitor<RubyNode> {
188188

189189
public static final int NO_FRAME_ON_STACK_MARKER = Translator.NO_FRAME_ON_STACK_MARKER;
190190

191+
public static final Nodes.Node[] EMPTY_NODE_ARRAY = Nodes.Node.EMPTY_ARRAY;
192+
public static final Nodes.ParametersNode ZERO_PARAMETERS_NODE = new Nodes.ParametersNode(EMPTY_NODE_ARRAY,
193+
EMPTY_NODE_ARRAY, null, EMPTY_NODE_ARRAY, EMPTY_NODE_ARRAY, null, null, 0, 0);
194+
191195
public static final RescueNode[] EMPTY_RESCUE_NODE_ARRAY = new RescueNode[0];
192196

193197
protected static final short NO_FLAGS = 0;
@@ -415,7 +419,7 @@ public RubyNode visitBeginNode(Nodes.BeginNode node) {
415419

416420
private RescueNode translateExceptionNodes(ArrayList<Nodes.Node> exceptionNodes, Nodes.RescueNode rescueClause) {
417421

418-
final Nodes.Node[] exceptionNodesArray = exceptionNodes.toArray(Nodes.Node.EMPTY_ARRAY);
422+
final Nodes.Node[] exceptionNodesArray = exceptionNodes.toArray(EMPTY_NODE_ARRAY);
419423
final RubyNode[] handlingClasses = translate(exceptionNodesArray);
420424

421425
RubyNode translatedBody;
@@ -482,8 +486,8 @@ private RubyNode translateBlockAndLambda(Nodes.Node node, Nodes.BlockParametersN
482486
for (int i = 1; i <= max; i++) {
483487
requireds[i - 1] = new Nodes.RequiredParameterNode("_" + i, 0, 0);
484488
}
485-
parameters = new Nodes.ParametersNode(requireds, Nodes.Node.EMPTY_ARRAY, null, Nodes.Node.EMPTY_ARRAY,
486-
Nodes.Node.EMPTY_ARRAY, null, null, 0, 0);
489+
parameters = new Nodes.ParametersNode(requireds, EMPTY_NODE_ARRAY, null, EMPTY_NODE_ARRAY,
490+
EMPTY_NODE_ARRAY, null, null, 0, 0);
487491
} else {
488492
// no numbered parameters
489493
parameters = null;
@@ -656,7 +660,7 @@ private ArgumentsAndBlockTranslation translateArgumentsAndBlock(Nodes.ArgumentsN
656660
String methodName) {
657661
final Nodes.Node[] arguments;
658662
if (argumentsNode == null) {
659-
arguments = Nodes.Node.EMPTY_ARRAY;
663+
arguments = EMPTY_NODE_ARRAY;
660664
} else {
661665
arguments = argumentsNode.arguments;
662666
}
@@ -1282,6 +1286,10 @@ public RubyNode visitForwardingSuperNode(Nodes.ForwardingSuperNode node) {
12821286

12831287
// TODO: could we use the ArgumentDescriptor[] stored in the SharedMethodInfo instead?
12841288
var parametersNode = environment.parametersNode;
1289+
if (parametersNode == null) {
1290+
// parametersNode == null for a method means zero parameters: https://github.com/ruby/prism/issues/1915
1291+
parametersNode = ZERO_PARAMETERS_NODE;
1292+
}
12851293
var reloadTranslator = new YARPReloadArgumentsTranslator(language, this, parametersNode);
12861294

12871295
final RubyNode[] reloadSequence = reloadTranslator.reload(parametersNode);

0 commit comments

Comments
 (0)