[ruby/prism] Warn **
interpreted as argument prefix
This PR makes Prism warn `**` interpreted as argument prefix. This carries a similar meaning to the following Ruby warning: ```console $ ruby -cwe "foo **bar" -e:1: warning: `**' interpreted as argument prefix Syntax OK ``` Previously, it did not issue a warning: ```console $ bundle exec ruby -rprism -ve "p Prism.parse('foo **bar').warnings" ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [] ``` From now on, it will issue a warning similar to Ruby's: ```console $ bundle exec ruby -rprism -ve "p Prism.parse('foo **bar').warnings" ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseWarning @type=:ambiguous_prefix_star_star @message="ambiguous `**` has been interpreted as an argument prefix" @location=#<Prism::Location @start_offset=4 @length=2 start_line=1> @level=:verbose>] ``` https://github.com/ruby/prism/commit/f6cb5c314c
This commit is contained in:
parent
7eea268b70
commit
824e3e6c3d
@ -234,6 +234,7 @@ warnings:
|
||||
- AMBIGUOUS_FIRST_ARGUMENT_MINUS
|
||||
- AMBIGUOUS_FIRST_ARGUMENT_PLUS
|
||||
- AMBIGUOUS_PREFIX_STAR
|
||||
- AMBIGUOUS_PREFIX_STAR_STAR
|
||||
- AMBIGUOUS_SLASH
|
||||
- COMPARISON_AFTER_COMPARISON
|
||||
- DOT_DOT_DOT_EOL
|
||||
|
@ -9610,7 +9610,10 @@ parser_lex(pm_parser_t *parser) {
|
||||
|
||||
pm_token_type_t type = PM_TOKEN_STAR_STAR;
|
||||
|
||||
if (lex_state_spcarg_p(parser, space_seen) || lex_state_beg_p(parser)) {
|
||||
if (lex_state_spcarg_p(parser, space_seen)) {
|
||||
pm_parser_warn_token(parser, &parser->current, PM_WARN_AMBIGUOUS_PREFIX_STAR_STAR);
|
||||
type = PM_TOKEN_USTAR_STAR;
|
||||
} else if (lex_state_beg_p(parser)) {
|
||||
type = PM_TOKEN_USTAR_STAR;
|
||||
}
|
||||
|
||||
|
@ -314,6 +314,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
||||
[PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS] = { "ambiguous first argument; put parentheses or a space even after `-` operator", PM_WARNING_LEVEL_VERBOSE },
|
||||
[PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS] = { "ambiguous first argument; put parentheses or a space even after `+` operator", PM_WARNING_LEVEL_VERBOSE },
|
||||
[PM_WARN_AMBIGUOUS_PREFIX_STAR] = { "ambiguous `*` has been interpreted as an argument prefix", PM_WARNING_LEVEL_VERBOSE },
|
||||
[PM_WARN_AMBIGUOUS_PREFIX_STAR_STAR] = { "ambiguous `**` has been interpreted as an argument prefix", PM_WARNING_LEVEL_VERBOSE },
|
||||
[PM_WARN_AMBIGUOUS_SLASH] = { "ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator", PM_WARNING_LEVEL_VERBOSE },
|
||||
[PM_WARN_COMPARISON_AFTER_COMPARISON] = { "comparison '%.*s' after comparison", PM_WARNING_LEVEL_VERBOSE },
|
||||
[PM_WARN_DOT_DOT_DOT_EOL] = { "... at EOL, should be parenthesized?", PM_WARNING_LEVEL_DEFAULT },
|
||||
|
Loading…
x
Reference in New Issue
Block a user