From 3b9085ad24d774231d24716ef1f6ceb292174cc6 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 25 Aug 2023 14:29:05 -0400 Subject: [PATCH] [ruby/yarp] Lambda params should not accept blocks https://github.com/ruby/yarp/commit/706daae0ac --- test/yarp/fixtures/lambda.txt | 4 ++ test/yarp/snapshots/lambda.txt | 70 +++++++++++++++++++++++++++++++++- yarp/yarp.c | 2 + 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/test/yarp/fixtures/lambda.txt b/test/yarp/fixtures/lambda.txt index 1071810aa1..5c21eafb24 100644 --- a/test/yarp/fixtures/lambda.txt +++ b/test/yarp/fixtures/lambda.txt @@ -5,3 +5,7 @@ ->(x: "b#{a}") { } ->(a: b * 3) {} + +-> foo = bar do end + +-> foo: bar do end diff --git a/test/yarp/snapshots/lambda.txt b/test/yarp/snapshots/lambda.txt index bf59e6aa68..23c4ebc072 100644 --- a/test/yarp/snapshots/lambda.txt +++ b/test/yarp/snapshots/lambda.txt @@ -1,6 +1,6 @@ -ProgramNode(0...51)( +ProgramNode(0...92)( [], - StatementsNode(0...51)( + StatementsNode(0...92)( [LambdaNode(0...14)( [:foo], (0...2), @@ -104,6 +104,72 @@ ProgramNode(0...51)( (47...48) ), nil + ), + LambdaNode(53...72)( + [:foo], + (53...55), + BlockParametersNode(56...65)( + ParametersNode(56...65)( + [], + [OptionalParameterNode(56...65)( + :foo, + (56...59), + (60...61), + CallNode(62...65)( + nil, + nil, + (62...65), + nil, + nil, + nil, + nil, + 2, + "bar" + ) + )], + [], + nil, + [], + nil, + nil + ), + [], + nil, + nil + ), + nil + ), + LambdaNode(74...92)( + [:foo], + (74...76), + BlockParametersNode(77...85)( + ParametersNode(77...85)( + [], + [], + [], + nil, + [KeywordParameterNode(77...85)( + (77...81), + CallNode(82...85)( + nil, + nil, + (82...85), + nil, + nil, + nil, + nil, + 2, + "bar" + ) + )], + nil, + nil + ), + [], + nil, + nil + ), + nil )] ) ) diff --git a/yarp/yarp.c b/yarp/yarp.c index fdcc303b7f..012f8136e5 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -11971,8 +11971,10 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { break; } case YP_CASE_PARAMETER: { + yp_accepts_block_stack_push(parser, false); yp_token_t opening = not_provided(parser); params = parse_block_parameters(parser, false, &opening, true); + yp_accepts_block_stack_pop(parser); break; } default: {