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

Wording of non-exhaustivity warning is confusing for beginners #7169

Closed
vicuna opened this issue Mar 8, 2016 · 3 comments
Closed

Wording of non-exhaustivity warning is confusing for beginners #7169

vicuna opened this issue Mar 8, 2016 · 3 comments
Assignees
Labels
Milestone

Comments

@vicuna
Copy link

vicuna commented Mar 8, 2016

Original bug ID: 7169
Reporter: @gasche
Assigned to: @gasche
Status: resolved (set by @gasche on 2016-07-01T15:17:26Z)
Resolution: fixed
Priority: normal
Severity: text
Version: 4.02.3
Target version: 4.03.1+dev
Fixed in version: 4.04.0 +dev / +beta1 / +beta2
Category: ~DO NOT USE (was: OCaml general)
Related to: #7504
Monitored by: @hcarty

Bug description

In discussion https://www.reddit.com/r/ocaml/comments/49g5yi/doubt_about_pattern_matching/ , a beginner has a two-field records {player1; player2} that he pattern-matches on, and he gets the following non-exhaustivity warning (one possible player value is not handled);

Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
{player1=Spock}

The beginner asks:

AFAIK, I can not create a record with only the first item:

utop[17]> let x = {player1=Spock};;
Error: Some record fields are undefined: player2

I think the beginner is right: this error message is confusing.

I would propose to rephrase it as follows:

Here is an example of a case that is not matched:
{player1=Spock}

(It would also possibly be a good idea to print partial record patterns with a trailing "; _" in this case, to highlight that this is not expected to be a constructible value, but I'm not sure whether that part is worth the trouble.)

@vicuna
Copy link
Author

vicuna commented Mar 8, 2016

Comment author: @Armael

I think it would be quite beneficial to print partial record patterns with a "; _". The fact that the pattern looks like a valid OCaml value was in my eyes the major cause of confusion.

@vicuna
Copy link
Author

vicuna commented Mar 9, 2016

Comment author: @Octachron

I also think that printing a trailing " _ " when the record pattern is not complete is a good idea. Moreover, it seems quite easy to implement this by reusing the warning on non-closed records.

I have proposed a PR to this effect in #501.

@vicuna
Copy link
Author

vicuna commented Jul 1, 2016

Comment author: @gasche

Solved by merging octachron's PR. Thanks a lot!

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