Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006438OCaml~DO NOT USE (was: OCaml general)public2014-05-22 03:062015-11-26 23:42
ReporterMartin Jambon 
Assigned Tomaranget 
StatusclosedResolutionwon't fix 
PlatformOSOS Version
Product Version4.01.0 
Target VersionFixed in Version 
Summary0006438: Pattern guard disables exhaustiveness check
DescriptionThe 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>
TagsNo tags attached.
Attached Files

- Relationships
has duplicate 0007059closedfrisch Warning 8 suppresses warning 25 

-  Notes
Martin Jambon (reporter)
2014-05-22 03:36

Correction: the problem I reported only occurs when all the clauses are guarded (do some people use that style on purpose?).
garrigue (manager)
2014-05-22 07:52

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.
maranget (manager)
2014-05-22 11:02

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.

lpw25 (developer)
2014-05-22 11:47

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

- Issue History
Date Modified Username Field Change
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
2015-11-26 23:42 garrigue Relationship added has duplicate 0007059
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker