Skip to content

Commit 133537c

Browse files
committed
Allow self for inline @rbs @ivar: self
1 parent 38bcc0c commit 133537c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3789,7 +3789,7 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
37893789
rbs_location_t *colon_loc = rbs_location_new(ALLOCATOR(), colon_range);
37903790

37913791
rbs_node_t *type = NULL;
3792-
if (!rbs_parse_type(parser, &type, false, false)) {
3792+
if (!rbs_parse_type(parser, &type, false, true)) {
37933793
return false;
37943794
}
37953795

test/rbs/inline_annotation_parsing_test.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ def test_parse__instance_variable
190190
assert_equal "Array[String]", annot.type.location.source
191191
assert_nil annot.comment_location
192192
end
193+
194+
Parser.parse_inline_leading_annotation("@rbs @self: self", 0...).tap do |annot|
195+
assert_instance_of AST::Ruby::Annotations::InstanceVariableAnnotation, annot
196+
assert_equal "@rbs @self: self", annot.location.source
197+
assert_equal "@rbs", annot.prefix_location.source
198+
assert_equal "@self", annot.ivar_name_location.source
199+
assert_equal :@self, annot.ivar_name
200+
assert_equal ":", annot.colon_location.source
201+
assert_equal "self", annot.type.location.source
202+
assert_nil annot.comment_location
203+
end
193204
end
194205

195206
def test_error__instance_variable
@@ -208,9 +219,5 @@ def test_error__instance_variable
208219
assert_raises RBS::ParsingError do
209220
Parser.parse_inline_leading_annotation("@rbs @name: void", 0...)
210221
end
211-
212-
assert_raises RBS::ParsingError do
213-
Parser.parse_inline_leading_annotation("@rbs @name: self", 0...)
214-
end
215222
end
216223
end

0 commit comments

Comments
 (0)