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

Autocorrect: when T::Boolean to when true, false #7023

Open
jez opened this issue May 17, 2023 · 2 comments
Open

Autocorrect: when T::Boolean to when true, false #7023

jez opened this issue May 17, 2023 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers
Milestone

Comments

@jez
Copy link
Collaborator

jez commented May 17, 2023

Input

→ View on sorbet.run

# typed: true
extend T::Sig

sig {params(x: T.any(T::Boolean, String)).void}
def example(x)
  case x
  when T::Boolean
    T.reveal_type(x)
  end

  case x
  when true, false
    T.reveal_type(x)
  end
end

Observed output

editor.rb:7: Call to method === on T::Boolean mistakes a type for a value https://srb.help/7030
     7 |  when T::Boolean
               ^^^^^^^^^^

editor.rb:8: Revealed type: T.any(TrueClass, FalseClass, String) https://srb.help/7014
     8 |    T.reveal_type(x)
            ^^^^^^^^^^^^^^^^
  Got T.any(TrueClass, FalseClass, String) originating from:
    editor.rb:5:
     5 |def example(x)
                    ^

editor.rb:13: Revealed type: T::Boolean https://srb.help/7014
    13 |    T.reveal_type(x)
            ^^^^^^^^^^^^^^^^
  Got T::Boolean originating from:
    editor.rb:5:
     5 |def example(x)
                    ^
    editor.rb:12:
    12 |  when true, false
                     ^^^^^
Errors: 3

Expected behavior

It would be great if we could get an autocorrect to convert the when T::Boolean into when true, false, because this is a common error.


@jez jez added bug Something isn't working good first issue Good for newcomers labels May 17, 2023
@jez jez modified the milestones: Autocompletion, Autocorrects May 17, 2023
@amomchilov
Copy link
Contributor

amomchilov commented May 18, 2023

Would it be reasonable to implement === so this "just works"?

There's a real stigma against a bool type in Ruby, but if we're going to have a type system that has a bool type anyway, may as well use it, right?

@jez
Copy link
Collaborator Author

jez commented Apr 15, 2024

We have resisted implementing support for === on type objects, because there are type objects where it doesn't make sense, for example generic types, proc types, T.self_type, etc. which can't be checked at runtime (docs).

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
Development

No branches or pull requests

2 participants