|Anonymous | Login | Signup for a new account||2015-07-31 05:11 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0006438||OCaml||OCaml general||public||2014-05-22 03:06||2014-06-03 14:45|
|Target Version||Fixed in Version|
|Summary||0006438: Pattern guard disables exhaustiveness check|
|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:
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 = <fun>
|Tags||No tags attached.|
Martin Jambon (reporter)
|Correction: the problem I reported only occurs when all the clauses are guarded (do some people use that style on purpose?).|
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.
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
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.
|Perhaps warning 25 could use the word "exhaustive" somewhere in its message, to make clear the connection with warning 8.|
|2014-05-22 03:06||Martin Jambon||New Issue|
|2014-05-22 03:36||Martin Jambon||Note Added: 0011538|
|2014-05-22 07:52||garrigue||Note Added: 0011539|
|2014-05-22 11:02||maranget||Note Added: 0011544|
|2014-05-22 11:47||lpw25||Note Added: 0011545|
|2014-05-30 14:02||shinwell||Assigned To||=> maranget|
|2014-05-30 14:02||shinwell||Status||new => confirmed|
|2014-06-03 14:45||maranget||Status||confirmed => closed|
|2014-06-03 14:45||maranget||Resolution||open => won't fix|
|Copyright © 2000 - 2011 MantisBT Group|