Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow overloading from super class methods #364

Merged
merged 1 commit into from
Aug 11, 2020

Conversation

soutaro
Copy link
Member

@soutaro soutaro commented Aug 11, 2020

RBS currently allows adding overloads only to methods defined in that class.

class Foo
  def foo: () -> Integer

  def foo: (String) -> String | ...         # OK
end

class Bar < Foo
  def foo: (Integer) -> String | ...        # Error 🚨
end

This makes writing signatures which provides a new module/class extending an existing module/class super difficult. One example is cmath. We want to write something like:

module CMath
  include Math

  def cos: (Complex) -> (Float | Complex)      # Add overload to accept Complex objects
         | ...                                 # While other numeric arguments are allowed as Math
end

This PR is to allow this.

  • Overloading ... are allowed for extending super class methods.
  • Overloading without primary (non-overloading) method definition is an error.

@soutaro soutaro merged commit 2e3e088 into master Aug 11, 2020
@soutaro soutaro deleted the overload-from-super-class branch August 11, 2020 05:02
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant