rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Type error with OptionParser#on method

Open ybiquitous opened this issue 4 years ago • 0 comments

Hi, thank you for providing the optparse types!

But, when I try the types with Steep, I get the following error: 😢

a.rb:6:2: [error] Cannot find compatible overloading of method `on` of type `::OptionParser`
│ Method types:
│   def on: (*::String) ?{ (*untyped) -> untyped } -> ::OptionParser
│         | (::String, (::Class | ::Array[::String] | ::Hash[::Symbol, untyped] | ::Regexp), ?::String) ?{ (*untyped) -> untyped } -> ::OptionParser
│         | (*::String) -> ::OptionParser
│         | (::String, (::Class | ::Array[::String] | ::Hash[::Symbol, untyped] | ::Regexp), ?::String) -> ::OptionParser
│
│ Diagnostic ID: Ruby::UnresolvedOverloading
│
ā””   opts.on("--name=NAME", "This is a name.", "Other explanations.", ["foo", "bar", "baz"]) do |name|
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Detected 1 problem from 1 file

This error occurs on the use of the OptionParser#on method. The next section describes more detailed reproduction.

Reproduction

Gemfile:

source "https://rubygems.org"
gem "rbs", "1.3.3"
gem "steep", "0.44.1"

Steepfile:

target :src do
  check "*.rb"
  library "optparse"
end

Ruby code:

require "optparse"

names = []

OptionParser.new do |opts|
  opts.on("--name=NAME", "This is a name.", "Other explanations.", ["foo", "bar", "baz"]) do |name|
    names << name
  end
end.parse!

p names

Run Steep:

$ bundle exec steep check
# Type checking files:

.........................................................F

a.rb:6:2: [error] Cannot find compatible overloading of method `on` of type `::OptionParser`
│ Method types:
│   def on: (*::String) ?{ (*untyped) -> untyped } -> ::OptionParser
│         | (::String, (::Class | ::Array[::String] | ::Hash[::Symbol, untyped] | ::Regexp), ?::String) ?{ (*untyped) -> untyped } -> ::OptionParser
│         | (*::String) -> ::OptionParser
│         | (::String, (::Class | ::Array[::String] | ::Hash[::Symbol, untyped] | ::Regexp), ?::String) -> ::OptionParser
│
│ Diagnostic ID: Ruby::UnresolvedOverloading
│
ā””   opts.on("--name=NAME", "This is a name.", "Other explanations.", ["foo", "bar", "baz"]) do |name|
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Detected 1 problem from 1 file

Run the Ruby code:

$ bundle exec ruby a.rb -h
Usage: a [options]
        --name=NAME                  This is a name.
                                     Other explanations.

$ bundle exec ruby a.rb --name=foo --name=bar --name=unknown
a.rb:9:in `<main>': invalid argument: --name=unknown (OptionParser::InvalidArgument)

$ bundle exec ruby a.rb --name=foo --name=bar
["foo", "bar"]

Environment

  • ruby: 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin20]
  • rbs: 1.3.3
  • steep: 0.44.1

I’m glad to provide you with more information if needed. Thank you. 😊

ybiquitous avatar Jul 29 '21 03:07 ybiquitous