rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Inconsistent behavior of interface inclusion

Open sharkovadarya opened this issue 4 years ago • 0 comments

Summary: When including two interfaces with a method of the same name in each, an error is thrown; when including an interface that includes them both, the last definition included is used instead. Seems inconsistent.

Example:

interface _Foo
  def a_method: () -> String
end

interface _Bar
  def a_method: () -> Integer
end

interface _FooBar
  include _Foo
  include _Bar
end

Let's include _Foo and _Bar:

class FooBar
  include _Foo
  include _Bar
end

and try to find out what its definition is: rbs method FooBar a_method.

An error is thrown:

in `block (4 levels) in build_instance': ./sig/file.rbs:16:2...16:14: Duplicated method definition: ::FooBar#a_method (RBS::DuplicatedInterfaceMethodDefinitionError)

Now let's include _FooBar, which includes both _Foo and _Bar:

class FooBar
  include _FooBar
end

Execute the same command: rbs method FooBar a_method and get a different output:

::FooBar#a_method
  defined_in: ::_Bar
  implementation: ::FooBar
  accessibility: public
  types:
      () -> ::Integer

So that's a case of inconsistent behavior. Since there's a whole separate class of errors dedicated to duplication of interface methods, I would assume this case of nested inclusion is not handled properly?

sharkovadarya avatar Mar 30 '21 13:03 sharkovadarya