Skip to content

Pattern guard disables exhaustiveness check #6438

@vicuna

Description

@vicuna

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 =

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions