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

Polymorphic variant pattern syntax is too permissive #7213

Closed
vicuna opened this issue Apr 5, 2016 · 5 comments
Closed

Polymorphic variant pattern syntax is too permissive #7213

vicuna opened this issue Apr 5, 2016 · 5 comments

Comments

@vicuna
Copy link

vicuna commented Apr 5, 2016

Original bug ID: 7213
Reporter: @yallop
Status: acknowledged (set by @gasche on 2016-04-05T14:43:15Z)
Resolution: open
Priority: normal
Severity: minor
Target version: later
Category: lexing and parsing
Monitored by: @gasche @diml @hcarty

Bug description

The following should be rejected, for consistency with the expression syntax:

function `A `B `C -> ()
@vicuna
Copy link
Author

vicuna commented Feb 17, 2017

Comment author: @xavierleroy

Note that it "works" also with normal variants:

type t = A of t | B of t | C
let f = function A B C -> ()

What do we gain by complicating the parser to reject this?

@vicuna
Copy link
Author

vicuna commented Feb 17, 2017

Comment author: @yallop

Well, it's a bit odd for constructor application to be right associative in patterns when expression application is left associative.

Oddness aside, bringing pattern and expression syntax into line could be used to simplify the parser, since the common bits could be factored out in some way, especially if we switch to menhir.

Even without refactoring, the change shouldn't complicate the parser. Something like the following should do it:

diff --git a/parsing/parser.mly b/parsing/parser.mly
index f444810..fbb0619 100644
--- a/parsing/parser.mly
+++ b/parsing/parser.mly
@@ -1733,3 +1733,3 @@ pattern_gen:
       { mkpat(Ppat_construct(mkrhs $1 1, Some $2)) }
-  | name_tag pattern %prec prec_constr_appl
+  | name_tag simple_pattern %prec prec_constr_appl
       { mkpat(Ppat_variant($1, Some $2)) }

@github-actions
Copy link

github-actions bot commented May 9, 2020

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label May 9, 2020
@Drup
Copy link
Contributor

Drup commented May 9, 2020

I ... actually like that feature. I use it occasionally (and I've seen it in the wild, so I'm not the only one). I'm not sure it's worth breaking existing code for this.

@trefis
Copy link
Contributor

trefis commented May 11, 2020

Agreed.

@trefis trefis closed this as completed May 11, 2020
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

3 participants