rbs
rbs copied to clipboard
Type error with OptionParser#on method
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. š