Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.