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

Bad error message for some pattern matching on extensible variants #6897

Closed
vicuna opened this issue Jun 7, 2015 · 6 comments
Closed

Bad error message for some pattern matching on extensible variants #6897

vicuna opened this issue Jun 7, 2015 · 6 comments
Assignees
Milestone

Comments

@vicuna
Copy link

vicuna commented Jun 7, 2015

Original bug ID: 6897
Reporter: @Drup
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-02-16T14:14:09Z)
Resolution: fixed
Priority: normal
Severity: minor
Target version: 4.02.3+dev
Fixed in version: 4.03.0+dev / +beta1
Category: typing
Monitored by: @Drup @gasche

Bug description

type t = ..
type t += A

let f x = match x with
| [A] -> 1
| ::::_ -> 3
| [] -> 2

This code gives the following error message:

File "bla.ml", line 4, characters 10-64:
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
extension::[]

The messages for extensible variants is usually far more understandable.

(Bug found by Adrien Nader)

File attachments

@vicuna
Copy link
Author

vicuna commented Jun 7, 2015

Comment author: @garrigue

I'm not sure what your problem is with this message.
To explain it, extension indicates an unknown constructor from an extensible sum type.
And in this case, [extension] aka extension::[] is precisely the case which is not handled.

@vicuna
Copy link
Author

vicuna commented Jun 8, 2015

Comment author: @Drup

For this program:

type t = ..
type t += A

let f x = match x with
| A -> 1

The error message is the following:

File "bla.ml", line 4, characters 10-33:
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
_
Matching over values of open types must include
a wild card pattern in order to be exhaustive.

This is a much better error message:

  • It explains clearly which feature is involved (open types) instead of relying on something more obscure like "extension" (extension of what ?)
  • It doesn't expose the user to a compiler generated name.

@vicuna
Copy link
Author

vicuna commented Jun 8, 2015

Comment author: @garrigue

I see that at some point a hack was added to replace the extension by a clearer message, but that this does not work when the pattern is more complex.
Will see what can be done.
Note that extension is not a computer generated name, but a fixed string which is supposed to convey to the user that there could be other cases in the extensible type.
Finding a better name could be a more direct solution.

@vicuna
Copy link
Author

vicuna commented Jun 17, 2015

Comment author: @alainfrisch

One could keep the pseudo pattern printed as today in the complex case, but when extension appear in it, add the additional text:

Matching over values of open types (marked as *extension* above) must include
a wild card pattern in order to be exhaustive.

I've attached a patch (which keeps the special case for the open type at toplevel).

@vicuna
Copy link
Author

vicuna commented Jun 17, 2015

Comment author: @garrigue

Fixed in trunk at 16176, as suggested by Alain.

@vicuna
Copy link
Author

vicuna commented Jun 17, 2015

Comment author: @gasche

(I think you forgot to update the testsuite's reference file, CI fails.)

@vicuna vicuna closed this as completed Feb 16, 2017
@vicuna vicuna added the typing label Mar 14, 2019
@vicuna vicuna added this to the 4.02.3 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants