Skip to content

Commit

Permalink
[ruby/prism] Fix unary not location
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Feb 12, 2024
1 parent 16b3907 commit c3886c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions prism/prism.c
Expand Up @@ -2891,7 +2891,7 @@ static pm_def_node_t *
pm_def_node_create(
pm_parser_t *parser,
pm_constant_id_t name,
const pm_location_t *name_loc,
const pm_token_t *name_loc,
pm_node_t *receiver,
pm_parameters_node_t *parameters,
pm_node_t *body,
Expand Down Expand Up @@ -2922,7 +2922,7 @@ pm_def_node_create(
.location = { .start = def_keyword->start, .end = end },
},
.name = name,
.name_loc = *name_loc,
.name_loc = PM_LOCATION_TOKEN_VALUE(name_loc),
.receiver = receiver,
.parameters = parameters,
.body = body,
Expand Down Expand Up @@ -15627,13 +15627,12 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
* methods to override the unary operators, we should ignore
* the @ in the same way we do for symbols.
*/
pm_constant_id_t name_id = pm_parser_constant_id_token(parser, &name);
pm_location_t name_loc = { .start = name.start, .end = parse_operator_symbol_name(&name) };
pm_constant_id_t name_id = pm_parser_constant_id_location(parser, name.start, parse_operator_symbol_name(&name));

return (pm_node_t *) pm_def_node_create(
parser,
name_id,
&name_loc,
&name,
receiver,
params,
statements,
Expand Down
4 changes: 2 additions & 2 deletions test/prism/snapshots/seattlerb/defn_unary_not.txt
Expand Up @@ -4,8 +4,8 @@
@ StatementsNode (location: (1,0)-(1,17))
└── body: (length: 1)
└── @ DefNode (location: (1,0)-(1,17))
├── name: :"!@"
├── name_loc: (1,4)-(1,5) = "!"
├── name: :!
├── name_loc: (1,4)-(1,6) = "!@"
├── receiver: ∅
├── parameters: ∅
├── body:
Expand Down

0 comments on commit c3886c1

Please sign in to comment.