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

sum-types: Surprising interaction between default cases and cases that follow it #1616

Closed
RyanGlScott opened this issue Jan 24, 2024 · 2 comments
Labels
bug Something not working correctly enums Issues related to enums

Comments

@RyanGlScott
Copy link
Contributor

On the sum-types branch (#1602), Cryptol will compile the following code without any warnings:

enum Foo = A | B

f : Foo -> Bit
f l =
  case l of
    _ -> True
    B -> False

Then f A will evaluate to True and f B will evaluate to False. This is not desirable, since we'd like _ to be a catch-all case that covers all patterns not listed above it. We should change the behavior so that:

  1. Both f A and f B evaluate to True.
  2. Cryptol emits a warning that the _ case overlaps with the B case.
@RyanGlScott RyanGlScott added bug Something not working correctly enums Issues related to enums labels Jan 24, 2024
@RyanGlScott
Copy link
Contributor Author

Actually, the sum-types branch makes overlapping patterns an error rather than a warning. For consistency, I'll change this proposal to just be:

  1. f is rejected with an error saying that the B case overlaps with the _ case.

There's no point in speculating what f B evaluates to in this case, since f won't compile in the first place.

@RyanGlScott
Copy link
Contributor Author

Fixed in ca85fac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something not working correctly enums Issues related to enums
Projects
None yet
Development

No branches or pull requests

1 participant