Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions snapshots/unary_method_calls.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@ ProgramNode (location: (1,0)-(2,5))
├── flags: ∅
├── locals: []
└── statements:
@ StatementsNode (location: (1,0)-(2,5))
├── flags: ∅
└── body: (length: 2)
├── @ CallNode (location: (1,0)-(1,5))
│ ├── flags: newline
│ ├── receiver:
│ │ @ IntegerNode (location: (1,0)-(1,2))
│ │ ├── flags: static_literal, decimal
│ │ └── value: 42
│ ├── call_operator_loc: (1,2)-(1,3) = "."
│ ├── name: :~
│ ├── message_loc: (1,3)-(1,5) = "~@"
│ ├── opening_loc: ∅
│ ├── arguments: ∅
│ ├── closing_loc: ∅
│ └── block: ∅
└── @ CallNode (location: (2,0)-(2,5))
├── flags: newline
├── receiver:
│ @ IntegerNode (location: (2,0)-(2,2))
│ ├── flags: static_literal, decimal
│ └── value: 42
├── call_operator_loc: (2,2)-(2,3) = "."
├── name: :!
├── message_loc: (2,3)-(2,5) = "!@"
├── opening_loc: ∅
├── arguments: ∅
├── closing_loc: ∅
└── block: ∅
10 changes: 8 additions & 2 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,8 @@ pm_call_node_binary_create(pm_parser_t *parser, pm_node_t *receiver, pm_token_t
return node;
}

static const uint8_t * parse_operator_symbol_name(const pm_token_t *);

/**
* Allocate and initialize a new CallNode node from a call expression.
*/
Expand Down Expand Up @@ -2749,7 +2751,11 @@ pm_call_node_call_create(pm_parser_t *parser, pm_node_t *receiver, pm_token_t *o
pm_node_flag_set((pm_node_t *)node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION);
}

node->name = pm_parser_constant_id_token(parser, message);
/**
* If the final character is `@` as is the case for `foo.~@`,
* we should ignore the @ in the same way we do for symbols.
*/
node->name = pm_parser_constant_id_location(parser, message->start, parse_operator_symbol_name(message));
return node;
}

Expand Down Expand Up @@ -19702,7 +19708,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
pm_parser_scope_pop(parser);

/**
* If the final character is @. As is the case when defining
* If the final character is `@` as is the case when defining
* methods to override the unary operators, we should ignore
* the @ in the same way we do for symbols.
*/
Expand Down
2 changes: 2 additions & 0 deletions test/prism/fixtures/unary_method_calls.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
42.~@
42.!@
3 changes: 3 additions & 0 deletions test/prism/ruby/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class ParserTest < TestCase
# Regex with \c escape
"unescaping.txt",
"seattlerb/regexp_esc_C_slash.txt",

# https://github.com/whitequark/parser/issues/1084
"unary_method_calls.txt",
]

# These files are failing to translate their lexer output into the lexer
Expand Down
1 change: 1 addition & 0 deletions test/prism/ruby/ruby_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RubyParserTest < TestCase
"spanning_heredoc.txt",
"symbols.txt",
"tilde_heredocs.txt",
"unary_method_calls.txt",
"unparser/corpus/literal/literal.txt",
"while.txt",
"whitequark/cond_eflipflop.txt",
Expand Down