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

Handle type arguments appropriately #19

Closed
mame opened this issue Nov 12, 2020 · 0 comments · Fixed by #21
Closed

Handle type arguments appropriately #19

mame opened this issue Nov 12, 2020 · 0 comments · Fixed by #21

Comments

@mame
Copy link
Member

mame commented Nov 12, 2020

Currently, TypeProf completely ignores Array[X] of class Bar[X] < Foo[Array[X]].

class Foo[X]
  def test_superclass: -> X
end

module M[X]
  def test_module: -> X
end

class Bar[X] < Foo[Array[X]]
  def initialize: (X) -> void
  include M[Integer]
end
obj = Bar.new("str")
p obj                 #=> Foo[String]
p obj.test_superclass #=> expected: Array[String], actual: String
p obj.test_module     #=> expected: Integer, actual: String

More practical example:

p({ a: 1 }.find { true }) #=> nil | untyped

because:

  • A class Hash includes Enumerable[[K, V], Hash[K, V]].
  • Enumerable#find returns Elem?. In this case, Elem == [K, V]
  • However, TypeProf don't know that Elem == [K, V], so it replaces Elem with untyped
mame added a commit to mame/typeprof that referenced this issue Nov 13, 2020
This is the first preparation for ruby#19. It also removes superclass from
ClassDef and moved the information to Type::Class.
mame added a commit to mame/typeprof that referenced this issue Nov 14, 2020
This is the first preparation for ruby#19. It also removes superclass from
ClassDef and moved the information to Type::Class.
mame added a commit that referenced this issue Nov 17, 2020
This is the first preparation for #19. It also removes superclass from
ClassDef and moved the information to Type::Class.
@mame mame closed this as completed in #21 Nov 17, 2020
mame added a commit that referenced this issue Nov 17, 2020
This is the first preparation for #19. It also removes superclass from
ClassDef and moved the information to Type::Class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant