[ruby/prism] Fix a diagnostic incompatibility
This PR fixes a diagnostic incompatibility when using no anonymous keyword rest parameter: ```ruby foo(**) ``` Note, although the actual update applies only to the `foo(**)` case, for reference, `foo(*)` and `foo(&) are also mentioned below. ## Ruby (Expected) ```console $ ruby -cve 'foo(*)' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] -e:1: no anonymous rest parameter -e: compile error (SyntaxError) $ ruby -cve 'foo(**)' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] -e:1: no anonymous keyword rest parameter -e: compile error (SyntaxError) $ ruby -cve 'foo(&)' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] -e:1: no anonymous block parameter -e: compile error (SyntaxError) ``` ## Prism (Actual) Before: ```console $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(*)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_star @message="unexpected `*` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=1 start_line=1> @level=:fatal>] $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(**)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:expect_expression_after_splat_hash @message="expected an expression after `**` in a hash" @location=#<Prism::Location @start_offset=4 @length=2 start_line=1> @level=:fatal>] $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(&)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_amp @message="unexpected `&` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=1 start_line=1> @level=:fatal>] ``` After: ```console $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(*)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_star @message="unexpected `*` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=1 start_line=1> @level=:fatal>] $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(**)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_star_star @message="unexpected `**` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=2 start_line=1> @level=:fatal>] $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(&)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_amp @message="unexpected `&` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=1 start_line=1> @level=:fatal>] ``` https://github.com/ruby/prism/commit/633c9d9fd4
This commit is contained in:
parent
72a613bc6a
commit
0a10702747
@ -135,6 +135,8 @@ module Prism
|
||||
Diagnostic.new(:error, :no_anonymous_blockarg, {}, diagnostic_location, [])
|
||||
when :argument_no_forwarding_star
|
||||
Diagnostic.new(:error, :no_anonymous_restarg, {}, diagnostic_location, [])
|
||||
when :argument_no_forwarding_star_star
|
||||
Diagnostic.new(:error, :no_anonymous_kwrestarg, {}, diagnostic_location, [])
|
||||
when :begin_lonely_else
|
||||
location = location.copy(length: 4)
|
||||
diagnostic_location = build_range(location, offset_cache)
|
||||
|
@ -15,6 +15,7 @@ errors:
|
||||
- ARGUMENT_NO_FORWARDING_AMP
|
||||
- ARGUMENT_NO_FORWARDING_ELLIPSES
|
||||
- ARGUMENT_NO_FORWARDING_STAR
|
||||
- ARGUMENT_NO_FORWARDING_STAR_STAR
|
||||
- ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT
|
||||
- ARGUMENT_SPLAT_AFTER_SPLAT
|
||||
- ARGUMENT_TERM_PAREN
|
||||
|
@ -6818,7 +6818,7 @@ pm_parser_scope_forwarding_all_check(pm_parser_t *parser, const pm_token_t * tok
|
||||
|
||||
static inline void
|
||||
pm_parser_scope_forwarding_keywords_check(pm_parser_t *parser, const pm_token_t * token) {
|
||||
pm_parser_scope_forwarding_param_check(parser, token, PM_SCOPE_PARAMETERS_FORWARDING_KEYWORDS, PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH);
|
||||
pm_parser_scope_forwarding_param_check(parser, token, PM_SCOPE_PARAMETERS_FORWARDING_KEYWORDS, PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,6 +97,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
||||
[PM_ERR_ARGUMENT_NO_FORWARDING_AMP] = { "unexpected `&` when the parent method is not forwarding", PM_ERROR_LEVEL_FATAL },
|
||||
[PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES] = { "unexpected `...` when the parent method is not forwarding", PM_ERROR_LEVEL_FATAL },
|
||||
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR] = { "unexpected `*` when the parent method is not forwarding", PM_ERROR_LEVEL_FATAL },
|
||||
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR] = { "unexpected `**` when the parent method is not forwarding", PM_ERROR_LEVEL_FATAL },
|
||||
[PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT] = { "unexpected `*` splat argument after a `**` keyword splat argument", PM_ERROR_LEVEL_FATAL },
|
||||
[PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT] = { "unexpected `*` splat argument after a `*` splat argument", PM_ERROR_LEVEL_FATAL },
|
||||
[PM_ERR_ARGUMENT_TERM_PAREN] = { "expected a `)` to close the arguments", PM_ERROR_LEVEL_FATAL },
|
||||
|
Loading…
x
Reference in New Issue
Block a user