rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Class.new losing type information on var

Open HoneyryderChuck opened this issue 4 years ago • 0 comments

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.

HoneyryderChuck avatar Jul 05 '21 14:07 HoneyryderChuck