rbs icon indicating copy to clipboard operation
rbs copied to clipboard

fix for inherited not supporting subclassing

Open HoneyryderChuck opened this issue 1 year ago • 3 comments

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?

HoneyryderChuck avatar Nov 19 '24 13:11 HoneyryderChuck

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?

  • Perhaps #1542?

ParadoxV5 avatar Nov 19 '24 17:11 ParadoxV5

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).

soutaro avatar Nov 28 '24 05:11 soutaro

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.

ParadoxV5 avatar Nov 28 '24 06:11 ParadoxV5