ruby / rbs

Type Signature for Ruby
Other
1.96k stars 215 forks source link

Enumerator::Chain#chain excepts Enumerator::Chain[T] as its arguments #1988

Closed tk0miya closed 2 months ago

tk0miya commented 2 months ago

The Enumerator::Chain#chain type expects an instance of Enumerator::Chain[T] as its argument. As a result, Steep detects nested #chain calls as a type error.

Input:

array = [1, 2, 3]
array.chain([4, 5, 6]).chain([7, 8, 9])

Result:

$ bundle exec steep check
# Type checking files:

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

app/example.rb:2:29: [error] Cannot pass a value of type `::Array[::Integer]` as an argument of type `::Enumerator::Chain[::Integer]`
│   ::Array[::Integer] <: ::Enumerator::Chain[::Integer]
│     ::Object <: ::Enumerator::Chain[::Integer]
│       ::BasicObject <: ::Enumerator::Chain[::Integer]
│
│ Diagnostic ID: Ruby::ArgumentTypeMismatch
│
└ array.chain([4, 5, 6]).chain([7, 8, 9])
                               ~~~~~~~~~

Detected 1 problem from 1 file

Environment:

tk0miya commented 2 months ago

Fixed by #1989. Closing.