Skip to content

Use char_is_identifier_start() to check for valid method name and fix serialization #2264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 24, 2024
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
2 changes: 1 addition & 1 deletion src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -11021,7 +11021,7 @@ parse_write(pm_parser_t *parser, pm_node_t *target, pm_token_t *operator, pm_nod
return target;
}

if (*call->message_loc.start == '_' || parser->encoding->alnum_char(call->message_loc.start, call->message_loc.end - call->message_loc.start)) {
if (char_is_identifier_start(parser, call->message_loc.start)) {
// When we get here, we have a method call, because it was
// previously marked as a method call but now we have an =. This
// looks like:
Expand Down
4 changes: 2 additions & 2 deletions templates/lib/prism/serialize.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ module Prism

constant =
if start.nobits?(1 << 31)
input.byteslice(start, length).to_sym
input.byteslice(start, length).force_encoding(@encoding).to_sym
else
serialized.byteslice(start & ((1 << 31) - 1), length).to_sym
serialized.byteslice(start & ((1 << 31) - 1), length).force_encoding(@encoding).to_sym
end

constant_pool[index] = constant
Expand Down
1 change: 1 addition & 0 deletions test/prism/fixtures/emoji_method_calls.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo.🌊 = 1
2 changes: 1 addition & 1 deletion test/prism/parse_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_parse_lex_file

relatives.each do |relative|
# These fail on TruffleRuby due to a difference in Symbol#inspect: :测试 vs :"测试"
next if RUBY_ENGINE == "truffleruby" and %w[seattlerb/bug202.txt seattlerb/magic_encoding_comment.txt].include?(relative)
next if RUBY_ENGINE == "truffleruby" and %w[emoji_method_calls.txt seattlerb/bug202.txt seattlerb/magic_encoding_comment.txt].include?(relative)

filepath = File.join(base, relative)
snapshot = File.expand_path(File.join("snapshots", relative), __dir__)
Expand Down
30 changes: 30 additions & 0 deletions test/prism/snapshots/emoji_method_calls.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.