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

Check exhaustiveness for int, str, ... -typed alts #1720

Closed
catamorphism opened this issue Jan 31, 2012 · 8 comments
Closed

Check exhaustiveness for int, str, ... -typed alts #1720

catamorphism opened this issue Jan 31, 2012 · 8 comments

Comments

@catamorphism
Copy link
Contributor

The patch I just pushed only handles exhaustiveness for alts on enum-typed data. alts on ints or strings or such can still be non-exhaustive. Fix this. (Obviously this would require inserting an '_' case most of the time.)

@nikomatsakis
Copy link
Contributor

I'm not 100% sure if this is desirable. This seems like a case where non-exhaustive by default could be the right thing. Adding "rfc" tag for that reason :)

@catamorphism
Copy link
Contributor Author

Fair enough. My opinion is that if we can prevent an uncaught exception from happening through static checks, we should. As with the other kind of alt, if the programmer's intent is that a certain case should never happen, they should make that explicit.

If we do make them non-exhaustive, I would advocate using a different keyword (as painful as that is) like "alt?" or something, so as not to give the impression that alts on non-algebraic data give the same static guarantee as the other sort.

@marijnh
Copy link
Contributor

marijnh commented Jan 31, 2012

This seems like a case where non-exhaustive by default could be the right thing.

I'd (still) prefer a single default (exhaustive) with the ability to explicitly mark individual alts as non-exhaustive.

@graydon
Copy link
Contributor

graydon commented Jan 31, 2012

Non-obvious. Consider this my expression of "please don't merge yet, we need to discuss more". Might be another argument for playing with the warn and error attributes in #1543.

@catamorphism
Copy link
Contributor Author

There's nothing to merge yet anyway :-) I'm not really in a rush to do anything about this, since this form of alt isn't as common as alts on enums.

@pcwalton
Copy link
Contributor

pcwalton commented Feb 1, 2012

I think we can basically just treat this like OCaml, where int and str are always considered nonexhaustive and you have to insert a _. (For str this is always true, for int it might as well be—nobody will write a 4-billion-case alt.)

@catamorphism
Copy link
Contributor Author

@pcwalton This is what seemed right to me, too.

@nikomatsakis
Copy link
Contributor

shrug I don't have a strong opinion. A single default is probably best. Least surprising.

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

No branches or pull requests

5 participants