Skip to content

InlineParser: @rbs @ivar annotation is reported as unused unless it is the first thing in the class body #3175

Description

@ksss

rbs 4.2.0

class Foo
  def bar; end

  # @rbs @a: Integer

  X = 1
end

RBS::InlineParser.parse reports UnusedInlineAnnotation for @rbs @a: Integer and no InstanceVariableMember is created. Moving the annotation above def bar makes it work.

Cause: InlineParser#visit_class_or_module_body calls comments.each_enclosed_block(child_node) on the body StatementsNode (whose line range spans from the first member to the last) and reports every block inside it as unused, before the class-level each_enclosed_block(node) that handles InstanceVariableAnnotation runs. Only blocks located before the first member survive.

https://github.com/ruby/rbs/blob/v4.2.0/lib/rbs/inline_parser.rb (visit_class_or_module_body)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions