`Class.new(Superclass)` cannot be assigned to a `Superclass`
When declaring a signature such as:
module Foo
Bar: StandardError
end
This code will return the error "Cannot assign a value of type ::Class to a constant of type StandardError"
module Foo
Bar = Class.new(StandardError)
end
This makes sense if we treat Class as any other class, but could it be possible to introduce specific behaviour in this case so that Bar is typed to StandardError, or an anonymous class that inherits from StandardError ?
I think that could be solved with a standard type declaration like this
module Foo
class Bar < StandardError
end
end
another way to do it is a module/class alias
module Foo
class Bar = StandardError
end
Thanks for your suggestions ! The two suggestions give the same output:
lib/playground/playground.rb:2:2: [error] Cannot assign a value of type `::Class` to a constant of type `singleton(::Foo::Bar)`
│ ::Class <: singleton(::Foo::Bar)
│ ::Module <: singleton(::Foo::Bar)
│ ::Object <: singleton(::Foo::Bar)
│ ::BasicObject <: singleton(::Foo::Bar)
│
│ Diagnostic ID: Ruby::IncompatibleAssignment
│
└ Bar = Class.new(StandardError)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I think it works on the current master. Not sure about already released versions