Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix for inherited not supporting subclassing #2091

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HoneyryderChuck
Copy link
Contributor

@HoneyryderChuck HoneyryderChuck commented Nov 19, 2024

the arg of inherited is a subclass of the current class, not (just) a ::Class.

There's also a similar limitation in Kernel#class definition, where def class: () -> Class should map out to something more useful, i.e. def class: () -> instance_class, but that would require support for a new keyword, and there may be other limitations?

the arg of inherited is a subclass of the current class, not (just) a ::Class
@ParadoxV5
Copy link
Contributor

There's also a similar limitation in Kernel#class definition, where def class: () -> Class should map out to something more useful, i.e. def class: () -> instance_class, but that would require support for a new keyword, and there may be other limitations?

@soutaro
Copy link
Member

soutaro commented Nov 28, 2024

Unfortunately, it doesn't work with the current instance type semantics.

This is an output to type check def Object.inherited(klass) = klass.fooo.

test.rb:1:36: [error] Type `::Object` does not have method `fooo`
│ Diagnostic ID: Ruby::NoMethod
│
└ def Object.inherited(klass) = klass.fooo
                                      ~~~~

The instance type is resolved to Object, not singleton(Object).

@ParadoxV5
Copy link
Contributor

test.rb:1:36: [error] Type `::Object` does not have method `fooo`
│ Diagnostic ID: Ruby::NoMethod
│
└ def Object.inherited(klass) = klass.fooo
                                      ~~~~

The instance type is resolved to Object, not singleton(Object).

This hints that singleton(Object) only reads from Object RBS and doesn’t consider itself an instance of Class; this is an oversight.

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

Successfully merging this pull request may close these issues.

3 participants