soutaro / rbs-inline

Inline RBS type declaration
MIT License
250 stars 8 forks source link

@rbs! Embedding Ignored When Adjacent to Certain Nodes #147

Open pocket7878 opened 6 days ago

pocket7878 commented 6 days ago

On using embedding syntax adjacent to normal node, behavior is unexpected.

class Foo
  # @rbs! type t = String | Integer
  def foo
    "bar"
  end
end

Expected behavior

Expected to output both embedded code & normal code.

class Foo
  type t = String | Integer

  def foo: () -> untyped
end

Actual behavior

class Foo
  # @rbs! type t = String | Integer
  def foo: () -> untyped
end

System configuration

tk0miya commented 5 days ago

At this moment, only annotations related to method definitions are allowed (arguments, blocks, and return types).

For other annotations, a blank line is required before the method definition and its annotations:

class Foo
  # @rbs! type t = String | Integer

  def foo: () -> untyped
end

I'm not sure this is a bug or not. But it's needed at this moment.

pocket7878 commented 4 days ago

@tk0miya Thank you for your comment! After reporting this issue, I dived into the internal code. I found that embedding does not work when an adjacent line is handled by another rbs-inline process.

For example, this embedding works:

class Foo
  # @rbs! type t = String | Integer
  unsupported :code
end

This will produce:

class Foo
  type t = String | Integer
end