Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rbs/ast/ruby/comment_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def parse_annotation_lines(start_line, end_line, variables)
def trailing_annotation(variables)
if trailing?
comment = comments[0] or raise
if comment.location.slice.start_with?(/#[:\[]/)
if comment.location.slice.start_with?("#:", "#[")
begin
Parser.parse_inline_trailing_annotation(comment_buffer, 0...comment_buffer.last_position, variables: variables)
rescue ParsingError => error
Expand Down
12 changes: 12 additions & 0 deletions test/rbs/inline_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,18 @@ class Foo
end
end

def test_error__attr_type_with_invalid_utf8
omit_on_truffle_ruby! "The C extension does not raise `RBS::ParsingError` for invalid UTF-8"
omit_on_jruby! "`Prism::Location#start_line_slice` returns `nil` on JRuby's prism"

["\xDD", "\xFF", "\xC3", "\xE2\x82"].each do |invalid_bytes|
source = "class Foo\n attr_reader :value #: Integer # #{invalid_bytes}\nend\n".dup.force_encoding(Encoding::UTF_8)
result = parse(source)

assert_instance_of RBS::InlineParser::Diagnostic::AnnotationSyntaxError, result.diagnostics.fetch(0)
end
end

def test_parse__class_with_super_class
result = parse(<<~RUBY)
class Child < Parent
Expand Down
Loading