diff --git a/lib/prism/debug.rb b/lib/prism/debug.rb index f5d19dc3df7..d0469adc9a7 100644 --- a/lib/prism/debug.rb +++ b/lib/prism/debug.rb @@ -133,6 +133,10 @@ def self.prism_locals(source) *params.keywords.grep(OptionalKeywordParameterNode).map(&:name), ] + if params.keyword_rest.is_a?(ForwardingParameterNode) + sorted.push(:*, :&, :"...") + end + sorted << AnonymousLocal if params.keywords.any? # Recurse down the parameter tree to find any destructured diff --git a/src/prism.c b/src/prism.c index 845f50f2165..cbf0d193562 100644 --- a/src/prism.c +++ b/src/prism.c @@ -5569,15 +5569,6 @@ pm_parser_local_add(pm_parser_t *parser, pm_constant_id_t constant_id) { } } -/** - * Add a local variable from a constant string to the current scope. - */ -static inline void -pm_parser_local_add_constant(pm_parser_t *parser, const char *start, size_t length) { - pm_constant_id_t constant_id = pm_parser_constant_id_constant(parser, start, length); - if (constant_id != 0) pm_parser_local_add(parser, constant_id); -} - /** * Add a local variable from a location to the current scope. */ @@ -11090,8 +11081,6 @@ parse_parameters( parser_lex(parser); if (allows_forwarding_parameters) { - pm_parser_local_add_constant(parser, "*", 1); - pm_parser_local_add_constant(parser, "&", 1); pm_parser_local_add_token(parser, &parser->previous); } diff --git a/test/prism/errors_test.rb b/test/prism/errors_test.rb index aeea04d04de..ee4736a0003 100644 --- a/test/prism/errors_test.rb +++ b/test/prism/errors_test.rb @@ -723,7 +723,7 @@ def test_method_parameters_after_arguments_forwarding nil ), nil, - [:*, :&, :"...", :a], + [:"...", :a], Location(), nil, Location(), @@ -800,7 +800,7 @@ def test_double_arguments_forwarding nil, ParametersNode([], [], nil, [], [], ForwardingParameterNode(), nil), nil, - [:*, :&, :"..."], + [:"..."], Location(), nil, Location(), diff --git a/test/prism/snapshots/methods.txt b/test/prism/snapshots/methods.txt index f89ebbd8e08..4bc8fead198 100644 --- a/test/prism/snapshots/methods.txt +++ b/test/prism/snapshots/methods.txt @@ -189,7 +189,7 @@ │ │ │ @ ForwardingParameterNode (location: (19,6)-(19,9)) │ │ └── block: ∅ │ ├── body: ∅ - │ ├── locals: [:*, :&, :"..."] + │ ├── locals: [:"..."] │ ├── def_keyword_loc: (19,0)-(19,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: (19,5)-(19,6) = "(" @@ -953,7 +953,7 @@ │ │ ├── block: ∅ │ │ ├── flags: ∅ │ │ └── name: :b - │ ├── locals: [:*, :&, :"..."] + │ ├── locals: [:"..."] │ ├── def_keyword_loc: (112,0)-(112,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: (112,5)-(112,6) = "(" @@ -995,7 +995,7 @@ │ │ ├── block: ∅ │ │ ├── flags: ∅ │ │ └── name: :b - │ ├── locals: [:*, :&, :"..."] + │ ├── locals: [:"..."] │ ├── def_keyword_loc: (114,0)-(114,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: (114,5)-(114,6) = "(" @@ -1216,7 +1216,7 @@ │ │ │ │ └── name: :b │ │ │ └── closing_loc: (136,24)-(136,25) = "}" │ │ └── closing_loc: (136,25)-(136,26) = "\"" - │ ├── locals: [:*, :&, :"..."] + │ ├── locals: [:"..."] │ ├── def_keyword_loc: (136,0)-(136,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: (136,5)-(136,6) = "(" diff --git a/test/prism/snapshots/seattlerb/defn_arg_forward_args.txt b/test/prism/snapshots/seattlerb/defn_arg_forward_args.txt index cfed07646c3..a7fa7797384 100644 --- a/test/prism/snapshots/seattlerb/defn_arg_forward_args.txt +++ b/test/prism/snapshots/seattlerb/defn_arg_forward_args.txt @@ -39,7 +39,7 @@ │ ├── block: ∅ │ ├── flags: ∅ │ └── name: :b - ├── locals: [:x, :*, :&, :"..."] + ├── locals: [:x, :"..."] ├── def_keyword_loc: (1,0)-(1,3) = "def" ├── operator_loc: ∅ ├── lparen_loc: (1,5)-(1,6) = "(" diff --git a/test/prism/snapshots/seattlerb/defn_args_forward_args.txt b/test/prism/snapshots/seattlerb/defn_args_forward_args.txt index 374ac8adfd7..0dff707b29c 100644 --- a/test/prism/snapshots/seattlerb/defn_args_forward_args.txt +++ b/test/prism/snapshots/seattlerb/defn_args_forward_args.txt @@ -48,7 +48,7 @@ │ ├── block: ∅ │ ├── flags: ∅ │ └── name: :b - ├── locals: [:x, :y, :z, :*, :&, :"..."] + ├── locals: [:x, :y, :z, :"..."] ├── def_keyword_loc: (1,0)-(1,3) = "def" ├── operator_loc: ∅ ├── lparen_loc: (1,5)-(1,6) = "(" diff --git a/test/prism/snapshots/seattlerb/defn_forward_args.txt b/test/prism/snapshots/seattlerb/defn_forward_args.txt index d86e27427af..6f14c0d1b10 100644 --- a/test/prism/snapshots/seattlerb/defn_forward_args.txt +++ b/test/prism/snapshots/seattlerb/defn_forward_args.txt @@ -34,7 +34,7 @@ │ ├── block: ∅ │ ├── flags: ∅ │ └── name: :b - ├── locals: [:*, :&, :"..."] + ├── locals: [:"..."] ├── def_keyword_loc: (1,0)-(1,3) = "def" ├── operator_loc: ∅ ├── lparen_loc: (1,5)-(1,6) = "(" diff --git a/test/prism/snapshots/seattlerb/defn_forward_args__no_parens.txt b/test/prism/snapshots/seattlerb/defn_forward_args__no_parens.txt index e0b6844969c..de87e9757a4 100644 --- a/test/prism/snapshots/seattlerb/defn_forward_args__no_parens.txt +++ b/test/prism/snapshots/seattlerb/defn_forward_args__no_parens.txt @@ -34,7 +34,7 @@ │ ├── block: ∅ │ ├── flags: ∅ │ └── name: :m - ├── locals: [:*, :&, :"..."] + ├── locals: [:"..."] ├── def_keyword_loc: (1,0)-(1,3) = "def" ├── operator_loc: ∅ ├── lparen_loc: ∅ diff --git a/test/prism/snapshots/whitequark/endless_method_forwarded_args_legacy.txt b/test/prism/snapshots/whitequark/endless_method_forwarded_args_legacy.txt index 2c048b39f7b..07ff89fe296 100644 --- a/test/prism/snapshots/whitequark/endless_method_forwarded_args_legacy.txt +++ b/test/prism/snapshots/whitequark/endless_method_forwarded_args_legacy.txt @@ -34,7 +34,7 @@ │ ├── block: ∅ │ ├── flags: ∅ │ └── name: :bar - ├── locals: [:*, :&, :"..."] + ├── locals: [:"..."] ├── def_keyword_loc: (1,0)-(1,3) = "def" ├── operator_loc: ∅ ├── lparen_loc: (1,7)-(1,8) = "(" diff --git a/test/prism/snapshots/whitequark/forward_arg.txt b/test/prism/snapshots/whitequark/forward_arg.txt index 5c87944e585..1a9aaec90b7 100644 --- a/test/prism/snapshots/whitequark/forward_arg.txt +++ b/test/prism/snapshots/whitequark/forward_arg.txt @@ -34,7 +34,7 @@ │ ├── block: ∅ │ ├── flags: ∅ │ └── name: :bar - ├── locals: [:*, :&, :"..."] + ├── locals: [:"..."] ├── def_keyword_loc: (1,0)-(1,3) = "def" ├── operator_loc: ∅ ├── lparen_loc: (1,7)-(1,8) = "(" diff --git a/test/prism/snapshots/whitequark/forward_arg_with_open_args.txt b/test/prism/snapshots/whitequark/forward_arg_with_open_args.txt index 4894f7b6cf0..7d7727ad27e 100644 --- a/test/prism/snapshots/whitequark/forward_arg_with_open_args.txt +++ b/test/prism/snapshots/whitequark/forward_arg_with_open_args.txt @@ -38,7 +38,7 @@ │ │ │ ├── block: ∅ │ │ │ ├── flags: ∅ │ │ │ └── name: :bar - │ │ ├── locals: [:*, :&, :"..."] + │ │ ├── locals: [:"..."] │ │ ├── def_keyword_loc: (1,1)-(1,4) = "def" │ │ ├── operator_loc: ∅ │ │ ├── lparen_loc: ∅ @@ -82,7 +82,7 @@ │ │ │ ├── block: ∅ │ │ │ ├── flags: ∅ │ │ │ └── name: :bar - │ │ ├── locals: [:*, :&, :"..."] + │ │ ├── locals: [:"..."] │ │ ├── def_keyword_loc: (5,1)-(5,4) = "def" │ │ ├── operator_loc: ∅ │ │ ├── lparen_loc: ∅ @@ -106,7 +106,7 @@ │ │ │ @ ForwardingParameterNode (location: (7,8)-(7,11)) │ │ └── block: ∅ │ ├── body: ∅ - │ ├── locals: [:*, :&, :"..."] + │ ├── locals: [:"..."] │ ├── def_keyword_loc: (7,0)-(7,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: ∅ @@ -144,7 +144,7 @@ │ │ ├── block: ∅ │ │ ├── flags: ∅ │ │ └── name: :bar - │ ├── locals: [:*, :&, :"..."] + │ ├── locals: [:"..."] │ ├── def_keyword_loc: (10,0)-(10,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: ∅ @@ -184,7 +184,7 @@ │ │ ├── block: ∅ │ │ ├── flags: ∅ │ │ └── name: :bar - │ ├── locals: [:a, :*, :&, :"..."] + │ ├── locals: [:a, :"..."] │ ├── def_keyword_loc: (12,0)-(12,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: ∅ @@ -224,7 +224,7 @@ │ │ ├── block: ∅ │ │ ├── flags: ∅ │ │ └── name: :bar - │ ├── locals: [:a, :*, :&, :"..."] + │ ├── locals: [:a, :"..."] │ ├── def_keyword_loc: (16,0)-(16,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: ∅ @@ -255,7 +255,7 @@ │ │ │ @ ForwardingParameterNode (location: (18,18)-(18,21)) │ │ └── block: ∅ │ ├── body: ∅ - │ ├── locals: [:a, :b, :*, :&, :"..."] + │ ├── locals: [:a, :b, :"..."] │ ├── def_keyword_loc: (18,0)-(18,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: ∅ @@ -300,7 +300,7 @@ │ │ ├── block: ∅ │ │ ├── flags: ∅ │ │ └── name: :bar - │ ├── locals: [:b, :*, :&, :"..."] + │ ├── locals: [:b, :"..."] │ ├── def_keyword_loc: (21,0)-(21,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: ∅ @@ -345,7 +345,7 @@ │ │ ├── block: ∅ │ │ ├── flags: ∅ │ │ └── name: :bar - │ ├── locals: [:b, :*, :&, :"..."] + │ ├── locals: [:b, :"..."] │ ├── def_keyword_loc: (25,0)-(25,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: ∅ @@ -385,7 +385,7 @@ │ ├── block: ∅ │ ├── flags: ∅ │ └── name: :bar - ├── locals: [:a, :*, :&, :"..."] + ├── locals: [:a, :"..."] ├── def_keyword_loc: (27,0)-(27,3) = "def" ├── operator_loc: ∅ ├── lparen_loc: (27,7)-(27,8) = "(" diff --git a/test/prism/snapshots/whitequark/forward_args_legacy.txt b/test/prism/snapshots/whitequark/forward_args_legacy.txt index e66d785bc17..5bca692fab0 100644 --- a/test/prism/snapshots/whitequark/forward_args_legacy.txt +++ b/test/prism/snapshots/whitequark/forward_args_legacy.txt @@ -34,7 +34,7 @@ │ │ ├── block: ∅ │ │ ├── flags: ∅ │ │ └── name: :bar - │ ├── locals: [:*, :&, :"..."] + │ ├── locals: [:"..."] │ ├── def_keyword_loc: (1,0)-(1,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: (1,7)-(1,8) = "(" @@ -56,7 +56,7 @@ │ │ │ @ ForwardingParameterNode (location: (3,8)-(3,11)) │ │ └── block: ∅ │ ├── body: ∅ - │ ├── locals: [:*, :&, :"..."] + │ ├── locals: [:"..."] │ ├── def_keyword_loc: (3,0)-(3,3) = "def" │ ├── operator_loc: ∅ │ ├── lparen_loc: (3,7)-(3,8) = "(" @@ -90,7 +90,7 @@ │ │ └── flags: ∅ │ ├── rparen_loc: (5,23)-(5,24) = ")" │ └── block: ∅ - ├── locals: [:*, :&, :"..."] + ├── locals: [:"..."] ├── def_keyword_loc: (5,0)-(5,3) = "def" ├── operator_loc: ∅ ├── lparen_loc: (5,7)-(5,8) = "(" diff --git a/test/prism/snapshots/whitequark/trailing_forward_arg.txt b/test/prism/snapshots/whitequark/trailing_forward_arg.txt index 450cd0f1058..62a884e0e54 100644 --- a/test/prism/snapshots/whitequark/trailing_forward_arg.txt +++ b/test/prism/snapshots/whitequark/trailing_forward_arg.txt @@ -43,7 +43,7 @@ │ ├── block: ∅ │ ├── flags: ∅ │ └── name: :bar - ├── locals: [:a, :b, :*, :&, :"..."] + ├── locals: [:a, :b, :"..."] ├── def_keyword_loc: (1,0)-(1,3) = "def" ├── operator_loc: ∅ ├── lparen_loc: (1,7)-(1,8) = "("