summaryrefslogtreecommitdiff
path: root/lib/prism/translation
diff options
context:
space:
mode:
authorKoichi ITO <koic.ito@gmail.com>2024-03-19 01:56:30 +0900
committergit <svn-admin@ruby-lang.org>2024-03-19 18:13:57 +0000
commit72a613bc6a7ac389e359fa9f0926ebfe395a9390 (patch)
tree42b0cffc1cf448bb1bc8c00c0749f567d37a05f9 /lib/prism/translation
parentcbcb2d46fc6d0971084b41df987480d2d9355328 (diff)
[ruby/prism] Fix a diagnostic incompatibility for `Prism::Translation::Parser`
This PR fixes a diagnostic incompatibility for `Prism::Translation::Parser` when using constant argument: ```ruby def foo(A) end ``` ## Parser gem (Expected) Displays `formal argument cannot be a constant (Parser::SyntaxError)`: ```console $ bundle exec ruby -Ilib -rparser/ruby33 -ve 'p Parser::Ruby33.parse("def foo(A) end")' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] (string):1:9: error: formal argument cannot be a constant (string):1: def foo(A) end (string):1: ^ /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/diagnostic/engine.rb:72: in `process': formal argument cannot be a constant (Parser::SyntaxError) from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/base.rb:274:in `diagnostic' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/ruby33.rb:12177:in `_reduce_663' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/racc-1.7.3/lib/racc/parser.rb:267:in `_racc_do_parse_c' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/racc-1.7.3/lib/racc/parser.rb:267:in `do_parse' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/base.rb:190:in `parse' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/base.rb:33:in `parse' from -e:1:in `<main>' ``` ## `Prism::Translation::Parser` (Actual) Previously, the error messages displayed by the Parser gem were different. Before: ```console $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'Prism::Translation::Parser33.parse("def foo(A) end")' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] (string):1:9: error: (string):1: def foo(A) end (string):1: ^ /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/diagnostic/engine.rb:72: in `process': Parser::SyntaxError (Parser::SyntaxError) from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `block in unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:216:in `each' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:216:in `unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:49:in `parse' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/base.rb:33:in `parse' from -e:1:in `<main>' ``` After: ```console $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'Prism::Translation::Parser33.parse("def foo(A) end")' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] (string):1:9: error: formal argument cannot be a constant (string):1: def foo(A) end (string):1: ^ /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/diagnostic/engine.rb:72: in `process': formal argument cannot be a constant (Parser::SyntaxError) from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `block in unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:216:in `each' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:216:in `unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:49:in `parse' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/base.rb:33:in `parse' from -e:1:in `<main>' ``` https://github.com/ruby/prism/commit/4f2af88520
Diffstat (limited to 'lib/prism/translation')
-rw-r--r--lib/prism/translation/parser.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/prism/translation/parser.rb b/lib/prism/translation/parser.rb
index 6a2a9bbf24..48a198504b 100644
--- a/lib/prism/translation/parser.rb
+++ b/lib/prism/translation/parser.rb
@@ -124,7 +124,7 @@ module Prism
when :argument_block_multi
Diagnostic.new(:error, :block_and_blockarg, {}, diagnostic_location, [])
when :argument_formal_constant
- Diagnostic.new(:error, :formal_argument, {}, diagnostic_location, [])
+ Diagnostic.new(:error, :argument_const, {}, diagnostic_location, [])
when :argument_formal_class
Diagnostic.new(:error, :argument_cvar, {}, diagnostic_location, [])
when :argument_formal_global