From 53c560156542915938ebebeac3e12352c04feb24 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Mon, 10 Jul 2023 10:54:12 -0400 Subject: [PATCH] [ruby/yarp] Fix endless method definitions binding power to accept args (#8051) --- test/yarp/fixtures/endless_methods.txt | 5 ++ test/yarp/snapshots/endless_methods.txt | 80 +++++++++++++++++++++++++ yarp/yarp.c | 2 +- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 test/yarp/fixtures/endless_methods.txt create mode 100644 test/yarp/snapshots/endless_methods.txt diff --git a/test/yarp/fixtures/endless_methods.txt b/test/yarp/fixtures/endless_methods.txt new file mode 100644 index 0000000000..8c2f2a30cc --- /dev/null +++ b/test/yarp/fixtures/endless_methods.txt @@ -0,0 +1,5 @@ +def foo = 1 + +def bar = A "" + +def method = 1 + 2 + 3 diff --git a/test/yarp/snapshots/endless_methods.txt b/test/yarp/snapshots/endless_methods.txt new file mode 100644 index 0000000000..2e67d9d76f --- /dev/null +++ b/test/yarp/snapshots/endless_methods.txt @@ -0,0 +1,80 @@ +ProgramNode(0...51)( + [], + StatementsNode(0...51)( + [DefNode(0...11)( + (4...7), + nil, + nil, + StatementsNode(10...11)([IntegerNode(10...11)()]), + [], + (0...3), + nil, + nil, + nil, + (8...9), + nil + ), + DefNode(13...27)( + (17...20), + nil, + nil, + StatementsNode(23...27)( + [CallNode(23...27)( + nil, + nil, + (23...24), + nil, + ArgumentsNode(25...27)( + [StringNode(25...27)((25...26), (26...26), (26...27), "")] + ), + nil, + nil, + 0, + "A" + )] + ), + [], + (13...16), + nil, + nil, + nil, + (21...22), + nil + ), + DefNode(29...51)( + (33...39), + nil, + nil, + StatementsNode(42...51)( + [CallNode(42...51)( + CallNode(42...47)( + IntegerNode(42...43)(), + nil, + (44...45), + nil, + ArgumentsNode(46...47)([IntegerNode(46...47)()]), + nil, + nil, + 0, + "+" + ), + nil, + (48...49), + nil, + ArgumentsNode(50...51)([IntegerNode(50...51)()]), + nil, + nil, + 0, + "+" + )] + ), + [], + (29...32), + nil, + nil, + nil, + (40...41), + nil + )] + ) +) diff --git a/yarp/yarp.c b/yarp/yarp.c index b725c051a3..3460dd2607 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -10941,7 +10941,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { context_push(parser, YP_CONTEXT_DEF); statements = (yp_node_t *) yp_statements_node_create(parser); - yp_node_t *statement = parse_expression(parser, YP_BINDING_POWER_ASSIGNMENT + 1, "Expected to be able to parse body of endless method definition."); + yp_node_t *statement = parse_expression(parser, YP_BINDING_POWER_DEFINED + 1, "Expected to be able to parse body of endless method definition."); if (accept(parser, YP_TOKEN_KEYWORD_RESCUE_MODIFIER)) { yp_token_t rescue_keyword = parser->previous;