Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class.new losing type information on var #701

Open
HoneyryderChuck opened this issue Jul 5, 2021 · 0 comments
Open

Class.new losing type information on var #701

HoneyryderChuck opened this issue Jul 5, 2021 · 0 comments

Comments

@HoneyryderChuck
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant