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

steep check raise UnresolvedOverloading for Array#to_h with block #328

Closed
ybiquitous opened this issue Mar 12, 2021 · 2 comments · Fixed by #359
Closed

steep check raise UnresolvedOverloading for Array#to_h with block #328

ybiquitous opened this issue Mar 12, 2021 · 2 comments · Fixed by #359
Labels

Comments

@ybiquitous
Copy link
Contributor

Description

steep check raises an UnresolvedOverloading error for the code using Array#to_h with a block.

Note: I'm not sure which this problem is caused by RBS or Steep, so I'll re-post this issue to ruby/rbs if the cause is RBS.

Here is the latest RBS of Array#to_h:

class Array
  def to_h: () -> Hash[untyped, untyped]
          | [T, S] () { (Elem) -> [T, S] } -> Hash[T, S]
end

Reproduction

a.rb
["abc", "d", ""].to_h { |e| [e, e.size] }
#=> {"abc"=>3, "d"=>1, ""=>0}
Steepfile
target :lib do
  check "*.rb"
end
$ bundle exec steep check a.rb
# Type checking files:

F

a.rb:1:0: [error] Cannot find compatible overloading of method `to_h` of type `::Array[::String]`
│ Method types:
│   def to_h: () -> ::Hash[untyped, untyped]
│           | [T, S] () { (::String) -> [T, S] } -> ::Hash[T, S]
│
│ Diagnostic ID: Ruby::UnresolvedOverloading
│
└ ["abc", "d", ""].to_h { |e| [e, e.size] }
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Detected 1 problem from 1 file

Environment

  • Ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
  • Steep: 0.42.0
  • RBS: rbs 1.1.0
@soutaro soutaro added the bug label Mar 12, 2021
@soutaro
Copy link
Owner

soutaro commented Mar 12, 2021

Thank you for reporting this. This should be a bug. You can workaround if you add a type annotation in the block:

["abc", "d", ""].to_h { |e|
  # @type block: [String, Integer]
  [e, e.size]
}

@ybiquitous
Copy link
Contributor Author

@soutaro Thanks for your feedback! The workaround works on my code. 👍

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

Successfully merging a pull request may close this issue.

2 participants