summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--prism/prism.c17
-rw-r--r--test/prism/fixtures/methods.txt2
-rw-r--r--test/prism/snapshots/methods.txt124
3 files changed, 114 insertions, 29 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 951223942d..971949ca53 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -14607,6 +14607,8 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
pm_token_t operator = parser->previous;
pm_node_t *expression = parse_value_expression(parser, PM_BINDING_POWER_NOT, PM_ERR_EXPECT_EXPRESSION_AFTER_LESS_LESS);
+ pm_constant_id_t old_param_name = parser->current_param_name;
+ parser->current_param_name = 0;
pm_parser_scope_push(parser, true);
accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON);
@@ -14626,6 +14628,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
pm_constant_id_list_t locals = parser->current_scope->locals;
pm_parser_scope_pop(parser);
+ parser->current_param_name = old_param_name;
pm_do_loop_stack_pop(parser);
return (pm_node_t *) pm_singleton_class_node_create(parser, &locals, &class_keyword, &operator, expression, statements, &parser->previous);
}
@@ -14652,6 +14655,8 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
superclass = NULL;
}
+ pm_constant_id_t old_param_name = parser->current_param_name;
+ parser->current_param_name = 0;
pm_parser_scope_push(parser, true);
if (inheritance_operator.type != PM_TOKEN_NOT_PROVIDED) {
expect2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON, PM_ERR_CLASS_UNEXPECTED_END);
@@ -14679,6 +14684,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
pm_constant_id_list_t locals = parser->current_scope->locals;
pm_parser_scope_pop(parser);
+ parser->current_param_name = old_param_name;
pm_do_loop_stack_pop(parser);
if (!PM_NODE_TYPE_P(constant_path, PM_CONSTANT_PATH_NODE) && !(PM_NODE_TYPE_P(constant_path, PM_CONSTANT_READ_NODE))) {
@@ -14696,10 +14702,12 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
context_push(parser, PM_CONTEXT_DEF_PARAMS);
parser_lex(parser);
+ pm_constant_id_t old_param_name = parser->current_param_name;
switch (parser->current.type) {
case PM_CASE_OPERATOR:
pm_parser_scope_push(parser, true);
+ parser->current_param_name = 0;
lex_state_set(parser, PM_LEX_STATE_ENDFN);
parser_lex(parser);
name = parser->previous;
@@ -14711,6 +14719,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
receiver = parse_variable_call(parser);
pm_parser_scope_push(parser, true);
+ parser->current_param_name = 0;
lex_state_set(parser, PM_LEX_STATE_FNAME);
parser_lex(parser);
@@ -14719,6 +14728,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
} else {
pm_refute_numbered_parameter(parser, parser->previous.start, parser->previous.end);
pm_parser_scope_push(parser, true);
+ parser->current_param_name = 0;
name = parser->previous;
}
@@ -14736,6 +14746,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
case PM_TOKEN_KEYWORD___LINE__:
case PM_TOKEN_KEYWORD___ENCODING__: {
pm_parser_scope_push(parser, true);
+ parser->current_param_name = 0;
parser_lex(parser);
pm_token_t identifier = parser->previous;
@@ -14803,11 +14814,13 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
receiver = (pm_node_t *) pm_parentheses_node_create(parser, &lparen, expression, &rparen);
pm_parser_scope_push(parser, true);
+ parser->current_param_name = 0;
name = parse_method_definition_name(parser);
break;
}
default:
pm_parser_scope_push(parser, true);
+ parser->current_param_name = 0;
name = parse_method_definition_name(parser);
break;
}
@@ -14920,6 +14933,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
}
pm_constant_id_list_t locals = parser->current_scope->locals;
+ parser->current_param_name = old_param_name;
pm_parser_scope_pop(parser);
return (pm_node_t *) pm_def_node_create(
@@ -15150,6 +15164,8 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
pm_parser_err_token(parser, &name, PM_ERR_MODULE_NAME);
}
+ pm_constant_id_t old_param_name = parser->current_param_name;
+ parser->current_param_name = 0;
pm_parser_scope_push(parser, true);
accept2(parser, PM_TOKEN_SEMICOLON, PM_TOKEN_NEWLINE);
pm_node_t *statements = NULL;
@@ -15167,6 +15183,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
pm_constant_id_list_t locals = parser->current_scope->locals;
pm_parser_scope_pop(parser);
+ parser->current_param_name = old_param_name;
expect1(parser, PM_TOKEN_KEYWORD_END, PM_ERR_MODULE_TERM);
diff --git a/test/prism/fixtures/methods.txt b/test/prism/fixtures/methods.txt
index fcaabd760d..3c382d07f0 100644
--- a/test/prism/fixtures/methods.txt
+++ b/test/prism/fixtures/methods.txt
@@ -180,3 +180,5 @@ def foo x:%(xx); end
def foo(...)
bar(&)
end
+
+def foo(bar = (def baz(bar) = bar; 1)) = 2
diff --git a/test/prism/snapshots/methods.txt b/test/prism/snapshots/methods.txt
index 08fc370018..1341308c22 100644
--- a/test/prism/snapshots/methods.txt
+++ b/test/prism/snapshots/methods.txt
@@ -1,8 +1,8 @@
-@ ProgramNode (location: (1,0)-(182,3))
+@ ProgramNode (location: (1,0)-(184,42))
├── locals: [:a, :c, :foo]
└── statements:
- @ StatementsNode (location: (1,0)-(182,3))
- └── body: (length: 68)
+ @ StatementsNode (location: (1,0)-(184,42))
+ └── body: (length: 69)
├── @ DefNode (location: (1,0)-(2,3))
│ ├── name: :foo
│ ├── name_loc: (1,4)-(1,7) = "foo"
@@ -1850,40 +1850,106 @@
│ ├── rparen_loc: ∅
│ ├── equal_loc: ∅
│ └── end_keyword_loc: (178,17)-(178,20) = "end"
- └── @ DefNode (location: (180,0)-(182,3))
+ ├── @ DefNode (location: (180,0)-(182,3))
+ │ ├── name: :foo
+ │ ├── name_loc: (180,4)-(180,7) = "foo"
+ │ ├── receiver: ∅
+ │ ├── parameters:
+ │ │ @ ParametersNode (location: (180,8)-(180,11))
+ │ │ ├── requireds: (length: 0)
+ │ │ ├── optionals: (length: 0)
+ │ │ ├── rest: ∅
+ │ │ ├── posts: (length: 0)
+ │ │ ├── keywords: (length: 0)
+ │ │ ├── keyword_rest:
+ │ │ │ @ ForwardingParameterNode (location: (180,8)-(180,11))
+ │ │ └── block: ∅
+ │ ├── body:
+ │ │ @ StatementsNode (location: (181,2)-(181,7))
+ │ │ └── body: (length: 1)
+ │ │ └── @ CallNode (location: (181,2)-(181,7))
+ │ │ ├── receiver: ∅
+ │ │ ├── call_operator_loc: ∅
+ │ │ ├── name: :bar
+ │ │ ├── message_loc: (181,2)-(181,5) = "bar"
+ │ │ ├── opening_loc: (181,5)-(181,6) = "("
+ │ │ ├── arguments: ∅
+ │ │ ├── closing_loc: (181,7)-(181,8) = ")"
+ │ │ ├── block:
+ │ │ │ @ BlockArgumentNode (location: (181,6)-(181,7))
+ │ │ │ ├── expression: ∅
+ │ │ │ └── operator_loc: (181,6)-(181,7) = "&"
+ │ │ └── flags: ∅
+ │ ├── locals: [:"..."]
+ │ ├── def_keyword_loc: (180,0)-(180,3) = "def"
+ │ ├── operator_loc: ∅
+ │ ├── lparen_loc: (180,7)-(180,8) = "("
+ │ ├── rparen_loc: (180,11)-(180,12) = ")"
+ │ ├── equal_loc: ∅
+ │ └── end_keyword_loc: (182,0)-(182,3) = "end"
+ └── @ DefNode (location: (184,0)-(184,42))
├── name: :foo
- ├── name_loc: (180,4)-(180,7) = "foo"
+ ├── name_loc: (184,4)-(184,7) = "foo"
├── receiver: ∅
├── parameters:
- │ @ ParametersNode (location: (180,8)-(180,11))
+ │ @ ParametersNode (location: (184,8)-(184,37))
│ ├── requireds: (length: 0)
- │ ├── optionals: (length: 0)
+ │ ├── optionals: (length: 1)
+ │ │ └── @ OptionalParameterNode (location: (184,8)-(184,37))
+ │ │ ├── name: :bar
+ │ │ ├── name_loc: (184,8)-(184,11) = "bar"
+ │ │ ├── operator_loc: (184,12)-(184,13) = "="
+ │ │ └── value:
+ │ │ @ ParenthesesNode (location: (184,14)-(184,37))
+ │ │ ├── body:
+ │ │ │ @ StatementsNode (location: (184,15)-(184,36))
+ │ │ │ └── body: (length: 2)
+ │ │ │ ├── @ DefNode (location: (184,15)-(184,33))
+ │ │ │ │ ├── name: :baz
+ │ │ │ │ ├── name_loc: (184,19)-(184,22) = "baz"
+ │ │ │ │ ├── receiver: ∅
+ │ │ │ │ ├── parameters:
+ │ │ │ │ │ @ ParametersNode (location: (184,23)-(184,26))
+ │ │ │ │ │ ├── requireds: (length: 1)
+ │ │ │ │ │ │ └── @ RequiredParameterNode (location: (184,23)-(184,26))
+ │ │ │ │ │ │ └── name: :bar
+ │ │ │ │ │ ├── optionals: (length: 0)
+ │ │ │ │ │ ├── rest: ∅
+ │ │ │ │ │ ├── posts: (length: 0)
+ │ │ │ │ │ ├── keywords: (length: 0)
+ │ │ │ │ │ ├── keyword_rest: ∅
+ │ │ │ │ │ └── block: ∅
+ │ │ │ │ ├── body:
+ │ │ │ │ │ @ StatementsNode (location: (184,30)-(184,33))
+ │ │ │ │ │ └── body: (length: 1)
+ │ │ │ │ │ └── @ LocalVariableReadNode (location: (184,30)-(184,33))
+ │ │ │ │ │ ├── name: :bar
+ │ │ │ │ │ └── depth: 0
+ │ │ │ │ ├── locals: [:bar]
+ │ │ │ │ ├── def_keyword_loc: (184,15)-(184,18) = "def"
+ │ │ │ │ ├── operator_loc: ∅
+ │ │ │ │ ├── lparen_loc: (184,22)-(184,23) = "("
+ │ │ │ │ ├── rparen_loc: (184,26)-(184,27) = ")"
+ │ │ │ │ ├── equal_loc: (184,28)-(184,29) = "="
+ │ │ │ │ └── end_keyword_loc: ∅
+ │ │ │ └── @ IntegerNode (location: (184,35)-(184,36))
+ │ │ │ └── flags: decimal
+ │ │ ├── opening_loc: (184,14)-(184,15) = "("
+ │ │ └── closing_loc: (184,36)-(184,37) = ")"
│ ├── rest: ∅
│ ├── posts: (length: 0)
│ ├── keywords: (length: 0)
- │ ├── keyword_rest:
- │ │ @ ForwardingParameterNode (location: (180,8)-(180,11))
+ │ ├── keyword_rest: ∅
│ └── block: ∅
├── body:
- │ @ StatementsNode (location: (181,2)-(181,7))
+ │ @ StatementsNode (location: (184,41)-(184,42))
│ └── body: (length: 1)
- │ └── @ CallNode (location: (181,2)-(181,7))
- │ ├── receiver: ∅
- │ ├── call_operator_loc: ∅
- │ ├── name: :bar
- │ ├── message_loc: (181,2)-(181,5) = "bar"
- │ ├── opening_loc: (181,5)-(181,6) = "("
- │ ├── arguments: ∅
- │ ├── closing_loc: (181,7)-(181,8) = ")"
- │ ├── block:
- │ │ @ BlockArgumentNode (location: (181,6)-(181,7))
- │ │ ├── expression: ∅
- │ │ └── operator_loc: (181,6)-(181,7) = "&"
- │ └── flags: ∅
- ├── locals: [:"..."]
- ├── def_keyword_loc: (180,0)-(180,3) = "def"
+ │ └── @ IntegerNode (location: (184,41)-(184,42))
+ │ └── flags: decimal
+ ├── locals: [:bar]
+ ├── def_keyword_loc: (184,0)-(184,3) = "def"
├── operator_loc: ∅
- ├── lparen_loc: (180,7)-(180,8) = "("
- ├── rparen_loc: (180,11)-(180,12) = ")"
- ├── equal_loc: ∅
- └── end_keyword_loc: (182,0)-(182,3) = "end"
+ ├── lparen_loc: (184,7)-(184,8) = "("
+ ├── rparen_loc: (184,37)-(184,38) = ")"
+ ├── equal_loc: (184,39)-(184,40) = "="
+ └── end_keyword_loc: ∅