Class.new losing type information on var
Open
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.2k
- Forks
- 256
- Avg merge
- 6d 17h
- Merged PRs (30d)
- 37
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the Ruby snippet in the issue under Steep, then trace how Class.new is typed and how the resulting class is checked. Done means the superclass type information is retained so the reported Class, options, and pl calls no longer produce type errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100