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

Suggest adding T.absurd when it's trivially possible #1749

Open
jez opened this issue Sep 10, 2019 · 2 comments
Open

Suggest adding T.absurd when it's trivially possible #1749

jez opened this issue Sep 10, 2019 · 2 comments
Labels
enhancement New feature or surprising current feature good first issue Good for newcomers

Comments

@jez
Copy link
Collaborator

jez commented Sep 10, 2019

Problem

This program already exhausts all the cases:

# typed: true
class A; end
class B; end

extend T::Sig

sig {params(ab: T.any(A, B)).void}
def foo(ab)
  case ab
  when A
    puts 'A'
  when B
    puts 'B'
  end
end

→ View on sorbet.run

Proposed solution

We could add an error (or autocorrect!) to add else T.absurd(ab) to the end of the case statement.

It's unclear when we should do this, and it could potentially be pretty noisy. Off the top of my head, I would think we should do it only for case statements (not if statements) that don't have an else. We'd have to see how much of a breaking change that would be.

@jez jez added the enhancement New feature or surprising current feature label Sep 10, 2019
@jez
Copy link
Collaborator Author

jez commented Sep 10, 2019

There is already precedent for this; I made a change similar to this on a branch that was never pushed or reviewed when I was driving up adoption of T.absurd internally on Stripe's monorepo.

@jez jez added the good first issue Good for newcomers label Sep 10, 2019
@jez
Copy link
Collaborator Author

jez commented Nov 11, 2020

Relates to #3634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or surprising current feature good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant