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

Pattern guard disables exhaustiveness check #6438

Closed
vicuna opened this issue May 22, 2014 · 4 comments
Closed

Pattern guard disables exhaustiveness check #6438

vicuna opened this issue May 22, 2014 · 4 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented May 22, 2014

Original bug ID: 6438
Reporter: @mjambon
Assigned to: @maranget
Status: closed (set by @maranget on 2014-06-03T12:45:17Z)
Resolution: won't fix
Priority: low
Severity: minor
Version: 4.01.0
Category: ~DO NOT USE (was: OCaml general)
Has duplicate: #7059
Monitored by: @gasche

Bug description

The example below is what happened in actual code. If there's a 'when' guard in a pattern match, exhaustiveness checking seems to be completely turned off, even if ignoring the guards could detect cases that are not covered.

A useful behavior would be, when some or all patterns are guarded, to check for exhaustiveness while ignoring all guards.

But using '-warn-error +8+25' instead of just '-warn-error +8' would work fine too. So maybe it's not worth bothering with this.

$ ocaml -warn-error +8
OCaml version 4.01.0

function Some x -> x;;

Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
None
Error: Some fatal warnings were triggered (1 occurrences)

function Some x when x = 0 -> x;;

Warning 25: bad style, all clauses in this pattern-matching are guarded.

  • : int option -> int =
@vicuna
Copy link
Author

vicuna commented May 22, 2014

Comment author: @mjambon

Correction: the problem I reported only occurs when all the clauses are guarded (do some people use that style on purpose?).

@vicuna
Copy link
Author

vicuna commented May 22, 2014

Comment author: @garrigue

This seems to be more a problem of design of the warnings.
Warning 25 implies warning 8, but some people do not even know its existence.
One could also generate a warning 8, but this does not add extra information.
I'm kind of wondering why the two warnings are distinct.

@vicuna
Copy link
Author

vicuna commented May 22, 2014

Comment author: @maranget

I do not really remember either :)

Consider however that warning 25 (all clauses are guarded)
is enabled by default and that programming that way is bad style...

For the record exhaustiveness check
is performed after having deleted all guarded clauses.
Hence, in the all-guarded clause case, warning 8 should always be activated
(a pattern matching with no clause always fails and thus should be considered
as non-exhaustive).
However, should such a all-guarded PM occur, programmer's reaction
should probably go beyond simply add some clauses. Hence the specific warning.
This is really very bad style.

If nobody objects, I'll close the issue.

--Luc

@vicuna
Copy link
Author

vicuna commented May 22, 2014

Comment author: @lpw25

Perhaps warning 25 could use the word "exhaustive" somewhere in its message, to make clear the connection with warning 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants