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

"fun (type t) when cond -> ..." should be rejected, maybe also "fun p when cond -> ..." #5939

Closed
vicuna opened this issue Mar 6, 2013 · 4 comments
Assignees
Labels
Milestone

Comments

@vicuna
Copy link

vicuna commented Mar 6, 2013

Original bug ID: 5939
Reporter: @alainfrisch
Assigned to: @damiendoligez
Status: closed (set by @xavierleroy on 2016-12-07T10:34:20Z)
Resolution: fixed
Priority: normal
Severity: minor
Target version: 4.02.0+dev
Fixed in version: 4.02.0+dev
Category: ~DO NOT USE (was: OCaml general)
Related to: #5936

Bug description

I found the following when trying to clean up the Parsetree by putting Pexp_when clauses where they belong in the AST:

fun (type t) when false -> 0;;

Fatal error: exit(0) outside appropriated catch
Fatal error: exception Misc.Fatal_error

The fix is not difficult (either in the parser or in the type-checker). But I'm wondering whether it make sense to keep the syntax:

fun pat when cond -> ...

which necessarily triggers warning 25 (bad style, all clauses in this pattern-matching are guarded).

The Parsetree cleanup would be a little bit simpler if we got rid of this form as well. I doubt anyone uses it. I propose to get rid of it, after (i) asking on the caml-list if anyone objects; (ii) using OPAM to check that the construction is indeed not used in any of the packaged software.

@vicuna
Copy link
Author

vicuna commented Apr 12, 2013

Comment author: @alainfrisch

#5936 seems to confirm that "fun pat when cond -> expr" can be removed with no harm.

@vicuna
Copy link
Author

vicuna commented Apr 15, 2013

Comment author: @alainfrisch

Commit 13528 on branch extension_points introduces an explicit representation of "cases" with an optional guard in order to get rid of the ugly Pexp_when. It also remove support for the construction "fun pat when cond -> expr". So, please don't remove it from the trunk, this will be part of the merge of extension_points.

@vicuna
Copy link
Author

vicuna commented Apr 29, 2013

Comment author: @alainfrisch

Setting Target Version = 4.02 (already fixed in extension_points, which will hopefully be merged in time for 4.02).

@vicuna
Copy link
Author

vicuna commented Jul 18, 2014

Comment author: @yallop

This is fixed in 4.02.

In 4.01:

fun (type t) when true -> ();;

Fatal error: exit(0) outside appropriated catch
Fatal error: exception Misc.Fatal_error

fun _ when true -> ();;

Characters 0-21:
fun _ when true -> ();;
^^^^^^^^^^^^^^^^^^^^^
Warning 25: bad style, all clauses in this pattern-matching are guarded.

In 4.02:

fun (type t) when true -> ();;

Characters 13-17:
fun (type t) when true -> ();;
^^^^
Error: Syntax error: operator expected.

fun _ when true -> ();;

Characters 6-10:
fun _ when true -> ();;
^^^^

There's a pull request open that updates the documentation:

ocaml/ocaml-manual#2

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