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

Invalid Array type with splat operator #498

Closed
pocke opened this issue Mar 4, 2022 · 0 comments · Fixed by #519
Closed

Invalid Array type with splat operator #498

pocke opened this issue Mar 4, 2022 · 0 comments · Fixed by #519

Comments

@pocke
Copy link
Contributor

pocke commented Mar 4, 2022

Steep determines an invalid type for Array literal with splat operator.

Example:

# test.rb
array = [*'0'..'9']

p 'a' + array[0]
# Steepfile
target :lib do
  check 'test.rb'
end
$ steep check
# Type checking files:

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

test.rb:3:8: [error] Cannot pass a value of type `::Range[::String]` as an argument of type `::string`
│   ::Range[::String] <: ::string
│     ::Range[::String] <: (::String | ::_ToStr)
│       ::Range[::String] <: ::String
│         ::Object <: ::String
│           ::BasicObject <: ::String
│
│ Diagnostic ID: Ruby::ArgumentTypeMismatch
│
└ p 'a' + array[0]
          ~~~~~~~~

Detected 1 problem from 1 file

The array[0] should be ::String, but Steep determines the type as ::Range[::String]. So it prints an unexpected type error.

On [*x], Ruby calls x.to_a and expand the returned array to the array literal. But Steep just uses x as the array literal's type parameter.

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

Successfully merging a pull request may close this issue.

1 participant