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

The order of classes inside T.any matters in type inference #2373

Closed
marianosimone opened this issue Dec 19, 2019 · 0 comments · Fixed by #3974
Closed

The order of classes inside T.any matters in type inference #2373

marianosimone opened this issue Dec 19, 2019 · 0 comments · Fixed by #3974
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@marianosimone
Copy link
Collaborator

marianosimone commented Dec 19, 2019

Input

→ View on sorbet.run

# typed: true
emptiable = T.let(nil, T.nilable(T.any(String, T::Array[String])))
emptiable&.empty? # OK, expected!

not_emptiable_shadowed =  T.let(nil, T.nilable(T.any(String, Float, T::Array[String])))
not_emptiable_shadowed&.empty? # OK, but shouldn't be!

not_emptiable_not_shadowed =  T.let(nil, T.nilable(T.any(String, T::Array[String], Float)))
not_emptiable_not_shadowed&.empty? # Not OK, expected!

Observed output

editor.rb:9: Method empty? does not exist on Float component of T.any(T::Array[String], String, Float) https://srb.help/7003
     9 |not_emptiable_not_shadowed&.empty? # Not OK, expected!
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 1

Expected behavior

I'd expect not_emptiable_shadowed to also error out statically when trying to call empty?, as Float doesn't have an empty? method, which makes it crash at runtime if the value is indeed a Float

@marianosimone marianosimone added bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team labels Dec 19, 2019
@jez jez added good first issue Good for newcomers and removed unconfirmed This issue has not yet been confirmed by the Sorbet team labels Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
2 participants