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

Spurious 'E' warning (fragile pattern-matching) #4073

Closed
vicuna opened this issue Jul 28, 2006 · 1 comment
Closed

Spurious 'E' warning (fragile pattern-matching) #4073

vicuna opened this issue Jul 28, 2006 · 1 comment
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Jul 28, 2006

Original bug ID: 4073
Reporter: prevosto
Assigned to: @maranget
Status: closed (set by @maranget on 2006-09-21T14:34:34Z)
Resolution: fixed
Priority: normal
Severity: tweak
Version: 3.09.2
Category: ~DO NOT USE (was: OCaml general)
Monitored by: prevosto

Bug description

In certain cases, ocaml warns that a matching is fragile while it isn't:
is002447:~ $ ocaml -w E
Objective Caml version 3.09.2

type foo = A | B;;

type foo = A | B

let f = function A,_ | _, A -> A | B,B -> B;;

val f : foo * foo -> foo =

let f = function A,_ -> A | _,A -> A | B,B -> B;;

Characters 28-29:
Warning E: this pattern is fragile. It would hide
the addition of new constructors to the data types it matches.
let f = function A,_ -> A | _,A -> A | B,B -> B;;
^
val f : foo * foo -> foo =

The two definitions of f are equivalent. Moreover, if we indeed add a constructor, the matching becomes incomplete (but it is flagged as fragile, which is a bit contradictory):

type bar = A | B | C;;

type bar = A | B | C

let f = function A,_ -> A | _,A -> A | B,B -> B;;

Characters 10-49:
Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
(C, (C|B))
Characters 30-31:
Warning E: this pattern is fragile. It would hide
the addition of new constructors to the data types it matches.
let f = function A,_ -> A | ,A -> A | B,B -> B;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
let f = function A,
-> A | _,A -> A | B,B -> B;;
^
val f : bar * bar -> bar =

@vicuna
Copy link
Author

vicuna commented Sep 21, 2006

Comment author: @maranget

I think I have closed the issue.

Fragile matchings are no implemented by following definition.

A matching is said to be fragile when the addition of a constructor
to one of the types it matches does not result in a 'non-exhaustive' warning.

'One of the types it matches' means that there is a constructor that
belongs to the said type in the matching.

Before, there was a vague notion of 'fragile pattern' with no clear
meaning.

--Luc

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

No branches or pull requests

2 participants