rbs
rbs copied to clipboard
Class.new losing type information on var
There's a failure I'm observing under steep, when using Class.new, similar to this bit:
class A
def self.options; {} ; end
def pl
puts "pl"
end
end
module Rando
def pl
klass = is_a?(A) ? self.class : A
klass = Class.new(klass)
# steep complains with:
# Cannot pass a value of type `(singleton(::Rando) | singleton(::A))` as an argument of type `::Class`
# (singleton(::Rando) | singleton(::A)) <: ::Class
# singleton(::Rando) <: ::Class
# ::Module <: ::Class
# ::Object <: ::Class
# ::BasicObject <: ::Class
klass.instance_variable_set(:@options, klass.options)
# steep complains again:
#
# Type `::Class` does not have method `options`
klass.plugin(pl, options, &blk).new
# Type `::Class` does not have method `pl`
end
Seems that this type of meta-programming makes it lose type information, although it should be clear, i.e. Class.new should inherit superclass type information.