diff options
author | TSUYUSATO Kitsune <[email protected]> | 2023-11-28 13:21:01 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-11-28 17:27:10 +0000 |
commit | f6fbb9fec5b411dae1b38b306a49399baa52aaec (patch) | |
tree | 3ef8b6316f9f22019a8d66972c7deabc712d0ac7 | |
parent | b5796d7b113a78b17e27f2ad23c209f4e2d2900b (diff) |
[ruby/prism] Use `0` for the default valie of `current_param_name`
https://github.com/ruby/prism/commit/896915de24
-rw-r--r-- | prism/parser.h | 6 | ||||
-rw-r--r-- | prism/prism.c | 8 | ||||
-rw-r--r-- | test/prism/errors_test.rb | 2 |
3 files changed, 4 insertions, 12 deletions
diff --git a/prism/parser.h b/prism/parser.h index 89963ab08a..8c98892ee9 100644 --- a/prism/parser.h +++ b/prism/parser.h @@ -675,11 +675,7 @@ struct pm_parser { /** This flag indicates that we are currently parsing a keyword argument. */ bool in_keyword_arg; - /** - * The current parameter name id on parsing its default value. - * Since this is used for detecting circular references, this is available - * only on `PM_CONTEXT_DEFAULT_PARAM`. - */ + /** The current parameter name id on parsing its default value. */ pm_constant_id_t current_param_name; /** diff --git a/prism/prism.c b/prism/prism.c index d0cfbef41d..951223942d 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -4040,8 +4040,6 @@ pm_local_variable_or_write_node_create(pm_parser_t *parser, pm_node_t *target, c return node; } -static bool context_p(pm_parser_t *parser, pm_context_t context); - /** * Allocate a new LocalVariableReadNode node. */ @@ -4049,10 +4047,7 @@ static pm_local_variable_read_node_t * pm_local_variable_read_node_create(pm_parser_t *parser, const pm_token_t *name, uint32_t depth) { pm_constant_id_t name_id = pm_parser_constant_id_token(parser, name); - if ( - context_p(parser, PM_CONTEXT_DEFAULT_PARAMS) && - parser->current_param_name == name_id - ) { + if (parser->current_param_name == name_id) { pm_parser_err_token(parser, name, PM_ERR_PARAMETER_CIRCULAR); } @@ -16958,6 +16953,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm .encoding_changed = false, .pattern_matching_newlines = false, .in_keyword_arg = false, + .current_param_name = 0, .semantic_token_seen = false, .frozen_string_literal = false, .suppress_warnings = false diff --git a/test/prism/errors_test.rb b/test/prism/errors_test.rb index 9c96725463..87fe0406ef 100644 --- a/test/prism/errors_test.rb +++ b/test/prism/errors_test.rb @@ -1836,7 +1836,7 @@ module Prism proc { |foo = foo| } proc { |foo: foo| } RUBY - message = 'Invalid circular reference in a default parameter' + message = 'Parameter default value references itself' assert_errors expression(source), source, [ [message, 14..17], [message, 37..40], |