Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006438OCamlOCaml generalpublic2014-05-22 03:062014-06-03 14:45
ReporterMartin Jambon 
Assigned Tomaranget 
PrioritylowSeverityminorReproducibilityalways
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:
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 = <fun>
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0011538)
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?).
(0011539)
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.
(0011544)
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.


--Luc
(0011545)
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


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker