From 9bd99cc171a8c226ea330f45a51fb3345813c6b4 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 16 Oct 2023 15:47:02 -0400 Subject: [PATCH] [ruby/prism] Fix up super with a blockarg https://github.com/ruby/prism/commit/0ea19ed823 --- prism/prism.c | 6 +- test/prism/fixtures/super.txt | 10 ++++ test/prism/snapshots/super.txt | 102 +++++++++++++++++++++++++++++---- 3 files changed, 105 insertions(+), 13 deletions(-) diff --git a/prism/prism.c b/prism/prism.c index b2484d6ed7..d2d153b2c4 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -13150,7 +13150,11 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) { pm_arguments_t arguments = PM_EMPTY_ARGUMENTS; parse_arguments_list(parser, &arguments, true); - if (arguments.opening_loc.start == NULL && arguments.arguments == NULL) { + if ( + arguments.opening_loc.start == NULL && + arguments.arguments == NULL && + ((arguments.block == NULL) || PM_NODE_TYPE_P(arguments.block, PM_BLOCK_NODE)) + ) { return (pm_node_t *) pm_forwarding_super_node_create(parser, &keyword, &arguments); } diff --git a/test/prism/fixtures/super.txt b/test/prism/fixtures/super.txt index b685035970..cd7aaf992e 100644 --- a/test/prism/fixtures/super.txt +++ b/test/prism/fixtures/super.txt @@ -5,3 +5,13 @@ super() super(1) super(1, 2, 3) + +super &:foo + +super(&:foo) + +super {} + +super(1, 2, 3) {} + +super(1, 2, 3, &:foo) diff --git a/test/prism/snapshots/super.txt b/test/prism/snapshots/super.txt index 24a7ae81a9..3ce771d349 100644 --- a/test/prism/snapshots/super.txt +++ b/test/prism/snapshots/super.txt @@ -1,8 +1,8 @@ -@ ProgramNode (location: (1,0)-(7,14)) +@ ProgramNode (location: (1,0)-(17,20)) ├── locals: [] └── statements: - @ StatementsNode (location: (1,0)-(7,14)) - └── body: (length: 4) + @ StatementsNode (location: (1,0)-(17,20)) + └── body: (length: 9) ├── @ ForwardingSuperNode (location: (1,0)-(1,5)) │ └── block: ∅ ├── @ SuperNode (location: (3,0)-(3,7)) @@ -21,17 +21,95 @@ │ │ └── flags: decimal │ ├── rparen_loc: (5,7)-(5,8) = ")" │ └── block: ∅ - └── @ SuperNode (location: (7,0)-(7,14)) - ├── keyword_loc: (7,0)-(7,5) = "super" - ├── lparen_loc: (7,5)-(7,6) = "(" + ├── @ SuperNode (location: (7,0)-(7,14)) + │ ├── keyword_loc: (7,0)-(7,5) = "super" + │ ├── lparen_loc: (7,5)-(7,6) = "(" + │ ├── arguments: + │ │ @ ArgumentsNode (location: (7,6)-(7,13)) + │ │ └── arguments: (length: 3) + │ │ ├── @ IntegerNode (location: (7,6)-(7,7)) + │ │ │ └── flags: decimal + │ │ ├── @ IntegerNode (location: (7,9)-(7,10)) + │ │ │ └── flags: decimal + │ │ └── @ IntegerNode (location: (7,12)-(7,13)) + │ │ └── flags: decimal + │ ├── rparen_loc: (7,13)-(7,14) = ")" + │ └── block: ∅ + ├── @ SuperNode (location: (9,0)-(9,11)) + │ ├── keyword_loc: (9,0)-(9,5) = "super" + │ ├── lparen_loc: ∅ + │ ├── arguments: ∅ + │ ├── rparen_loc: ∅ + │ └── block: + │ @ BlockArgumentNode (location: (9,6)-(9,11)) + │ ├── expression: + │ │ @ SymbolNode (location: (9,7)-(9,11)) + │ │ ├── opening_loc: (9,7)-(9,8) = ":" + │ │ ├── value_loc: (9,8)-(9,11) = "foo" + │ │ ├── closing_loc: ∅ + │ │ └── unescaped: "foo" + │ └── operator_loc: (9,6)-(9,7) = "&" + ├── @ SuperNode (location: (11,0)-(11,11)) + │ ├── keyword_loc: (11,0)-(11,5) = "super" + │ ├── lparen_loc: (11,5)-(11,6) = "(" + │ ├── arguments: ∅ + │ ├── rparen_loc: (11,11)-(11,12) = ")" + │ └── block: + │ @ BlockArgumentNode (location: (11,6)-(11,11)) + │ ├── expression: + │ │ @ SymbolNode (location: (11,7)-(11,11)) + │ │ ├── opening_loc: (11,7)-(11,8) = ":" + │ │ ├── value_loc: (11,8)-(11,11) = "foo" + │ │ ├── closing_loc: ∅ + │ │ └── unescaped: "foo" + │ └── operator_loc: (11,6)-(11,7) = "&" + ├── @ ForwardingSuperNode (location: (13,0)-(13,8)) + │ └── block: + │ @ BlockNode (location: (13,6)-(13,8)) + │ ├── locals: [] + │ ├── parameters: ∅ + │ ├── body: ∅ + │ ├── opening_loc: (13,6)-(13,7) = "{" + │ └── closing_loc: (13,7)-(13,8) = "}" + ├── @ SuperNode (location: (15,0)-(15,17)) + │ ├── keyword_loc: (15,0)-(15,5) = "super" + │ ├── lparen_loc: (15,5)-(15,6) = "(" + │ ├── arguments: + │ │ @ ArgumentsNode (location: (15,6)-(15,13)) + │ │ └── arguments: (length: 3) + │ │ ├── @ IntegerNode (location: (15,6)-(15,7)) + │ │ │ └── flags: decimal + │ │ ├── @ IntegerNode (location: (15,9)-(15,10)) + │ │ │ └── flags: decimal + │ │ └── @ IntegerNode (location: (15,12)-(15,13)) + │ │ └── flags: decimal + │ ├── rparen_loc: (15,13)-(15,14) = ")" + │ └── block: + │ @ BlockNode (location: (15,15)-(15,17)) + │ ├── locals: [] + │ ├── parameters: ∅ + │ ├── body: ∅ + │ ├── opening_loc: (15,15)-(15,16) = "{" + │ └── closing_loc: (15,16)-(15,17) = "}" + └── @ SuperNode (location: (17,0)-(17,20)) + ├── keyword_loc: (17,0)-(17,5) = "super" + ├── lparen_loc: (17,5)-(17,6) = "(" ├── arguments: - │ @ ArgumentsNode (location: (7,6)-(7,13)) + │ @ ArgumentsNode (location: (17,6)-(17,13)) │ └── arguments: (length: 3) - │ ├── @ IntegerNode (location: (7,6)-(7,7)) + │ ├── @ IntegerNode (location: (17,6)-(17,7)) │ │ └── flags: decimal - │ ├── @ IntegerNode (location: (7,9)-(7,10)) + │ ├── @ IntegerNode (location: (17,9)-(17,10)) │ │ └── flags: decimal - │ └── @ IntegerNode (location: (7,12)-(7,13)) + │ └── @ IntegerNode (location: (17,12)-(17,13)) │ └── flags: decimal - ├── rparen_loc: (7,13)-(7,14) = ")" - └── block: ∅ + ├── rparen_loc: (17,20)-(17,21) = ")" + └── block: + @ BlockArgumentNode (location: (17,15)-(17,20)) + ├── expression: + │ @ SymbolNode (location: (17,16)-(17,20)) + │ ├── opening_loc: (17,16)-(17,17) = ":" + │ ├── value_loc: (17,17)-(17,20) = "foo" + │ ├── closing_loc: ∅ + │ └── unescaped: "foo" + └── operator_loc: (17,15)-(17,16) = "&"