aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/yarp/fixtures/methods.txt3
-rw-r--r--test/yarp/snapshots/methods.txt86
-rw-r--r--yarp/yarp.c3
3 files changed, 60 insertions, 32 deletions
diff --git a/test/yarp/fixtures/methods.txt b/test/yarp/fixtures/methods.txt
index de17645bb5..ac561363f8 100644
--- a/test/yarp/fixtures/methods.txt
+++ b/test/yarp/fixtures/methods.txt
@@ -163,3 +163,6 @@ end
def foo(_a, _a, b, c)
end
+
+foo = 1
+def foo.bar; end
diff --git a/test/yarp/snapshots/methods.txt b/test/yarp/snapshots/methods.txt
index 6f89c81514..da62c74ddd 100644
--- a/test/yarp/snapshots/methods.txt
+++ b/test/yarp/snapshots/methods.txt
@@ -1,8 +1,8 @@
-@ ProgramNode (location: (0...1194))
-├── locals: [:a, :c]
+@ ProgramNode (location: (0...1220))
+├── locals: [:a, :c, :foo]
└── statements:
- @ StatementsNode (location: (0...1194))
- └── body: (length: 60)
+ @ StatementsNode (location: (0...1220))
+ └── body: (length: 62)
├── @ DefNode (location: (0...23))
│ ├── name: :foo
│ ├── name_loc: (4...7) = "foo"
@@ -1584,32 +1584,56 @@
│ ├── rparen_loc: (1147...1148) = ")"
│ ├── equal_loc: ∅
│ └── end_keyword_loc: (1164...1167) = "end"
- └── @ DefNode (location: (1169...1194))
- ├── name: :foo
- ├── name_loc: (1173...1176) = "foo"
- ├── receiver: ∅
- ├── parameters:
- │ @ ParametersNode (location: (1177...1189))
- │ ├── requireds: (length: 4)
- │ │ ├── @ RequiredParameterNode (location: (1177...1179))
- │ │ │ └── name: :_a
- │ │ ├── @ RequiredParameterNode (location: (1181...1183))
- │ │ │ └── name: :_a
- │ │ ├── @ RequiredParameterNode (location: (1185...1186))
- │ │ │ └── name: :b
- │ │ └── @ RequiredParameterNode (location: (1188...1189))
- │ │ └── name: :c
- │ ├── optionals: (length: 0)
- │ ├── rest: ∅
- │ ├── posts: (length: 0)
- │ ├── keywords: (length: 0)
- │ ├── keyword_rest: ∅
- │ └── block: ∅
+ ├── @ DefNode (location: (1169...1194))
+ │ ├── name: :foo
+ │ ├── name_loc: (1173...1176) = "foo"
+ │ ├── receiver: ∅
+ │ ├── parameters:
+ │ │ @ ParametersNode (location: (1177...1189))
+ │ │ ├── requireds: (length: 4)
+ │ │ │ ├── @ RequiredParameterNode (location: (1177...1179))
+ │ │ │ │ └── name: :_a
+ │ │ │ ├── @ RequiredParameterNode (location: (1181...1183))
+ │ │ │ │ └── name: :_a
+ │ │ │ ├── @ RequiredParameterNode (location: (1185...1186))
+ │ │ │ │ └── name: :b
+ │ │ │ └── @ RequiredParameterNode (location: (1188...1189))
+ │ │ │ └── name: :c
+ │ │ ├── optionals: (length: 0)
+ │ │ ├── rest: ∅
+ │ │ ├── posts: (length: 0)
+ │ │ ├── keywords: (length: 0)
+ │ │ ├── keyword_rest: ∅
+ │ │ └── block: ∅
+ │ ├── body: ∅
+ │ ├── locals: [:_a, :b, :c]
+ │ ├── def_keyword_loc: (1169...1172) = "def"
+ │ ├── operator_loc: ∅
+ │ ├── lparen_loc: (1176...1177) = "("
+ │ ├── rparen_loc: (1189...1190) = ")"
+ │ ├── equal_loc: ∅
+ │ └── end_keyword_loc: (1191...1194) = "end"
+ ├── @ LocalVariableWriteNode (location: (1196...1203))
+ │ ├── name: :foo
+ │ ├── depth: 0
+ │ ├── name_loc: (1196...1199) = "foo"
+ │ ├── value:
+ │ │ @ IntegerNode (location: (1202...1203))
+ │ │ └── flags: decimal
+ │ └── operator_loc: (1200...1201) = "="
+ └── @ DefNode (location: (1204...1220))
+ ├── name: :bar
+ ├── name_loc: (1212...1215) = "bar"
+ ├── receiver:
+ │ @ LocalVariableReadNode (location: (1208...1211))
+ │ ├── name: :foo
+ │ └── depth: 0
+ ├── parameters: ∅
├── body: ∅
- ├── locals: [:_a, :b, :c]
- ├── def_keyword_loc: (1169...1172) = "def"
- ├── operator_loc: ∅
- ├── lparen_loc: (1176...1177) = "("
- ├── rparen_loc: (1189...1190) = ")"
+ ├── locals: []
+ ├── def_keyword_loc: (1204...1207) = "def"
+ ├── operator_loc: (1211...1212) = "."
+ ├── lparen_loc: ∅
+ ├── rparen_loc: ∅
├── equal_loc: ∅
- └── end_keyword_loc: (1191...1194) = "end"
+ └── end_keyword_loc: (1217...1220) = "end"
diff --git a/yarp/yarp.c b/yarp/yarp.c
index 6379ee50c5..c7dcf482f7 100644
--- a/yarp/yarp.c
+++ b/yarp/yarp.c
@@ -11806,12 +11806,12 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
name = parser->previous;
break;
case YP_TOKEN_IDENTIFIER: {
- yp_parser_scope_push(parser, true);
parser_lex(parser);
if (match_any_type_p(parser, 2, YP_TOKEN_DOT, YP_TOKEN_COLON_COLON)) {
receiver = parse_variable_call(parser);
+ yp_parser_scope_push(parser, true);
lex_state_set(parser, YP_LEX_STATE_FNAME);
parser_lex(parser);
@@ -11822,6 +11822,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
yp_diagnostic_list_append(&parser->error_list, parser->previous.start, parser->previous.end, YP_ERR_DEF_NAME_AFTER_RECEIVER);
}
} else {
+ yp_parser_scope_push(parser, true);
name = parser->previous;
}