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

Compiler fails to warn about pattern Top _ when Top is a 0-ary constructor #4675

Closed
vicuna opened this Issue Dec 17, 2008 · 4 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link
Collaborator

vicuna commented Dec 17, 2008

Original bug ID: 4675
Reporter: Pascal Cuoq
Status: closed (set by @damiendoligez on 2009-12-08T16:49:41Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.11.0+beta
Fixed in version: 3.12.0+dev
Category: ~DO NOT USE (was: OCaml general)
Has duplicate: #4717 #4835 #4911
Related to: #4052
Monitored by: lynxiamen "Etienne Millon" "Julien Signoles" "Richard Jones" @alainfrisch

Bug description

type t = Top | Base of int ;;

type t = Top | Base of int

let f x = match x with Base _ -> 0 | Top _ -> 1 ;;

Résultat obtenu :
val f : t -> int =

Résultat attendu :
Error: The constructor Top expects 0 argument(s),
but is here applied to 1 argument(s)

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 17, 2008

Comment author: @damiendoligez

This is a feature that was implemented to facilitate automatic generation of OCaml code...

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 17, 2008

Comment author: Pascal Cuoq

I can see how some camlp4 extensions may get lighter this way,
but the principle behind any single OCaml warning is that
it's better to alert the programmer at the first sign that she
might be confused about her program (the earlier the better),
and this feature is certainly not homogeneous with
this (desirable) general principle.

Shouldn't the pattern generated by camlp4 be something that
does not coincide with something that a human programmer might
write by accident and want to hear about? "Top " is already as
ugly as it gets, therefore if a camlp4 extension is generating this
it does not look like a very big stretch to force it
to generate "Top __" or "Top ((
))" or whatever other construct that

  1. would also work if the constructor had arguments, so as not to
    return to the initial problem, and
  2. no-one in her right mind would write.
@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jul 15, 2009

Comment author: Etienne Millon

I agree with Pascal Cuoq. It may be nice to factor some camlp4 code, but it creates a nasty compatibility issue.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Nov 6, 2009

Comment author: @damiendoligez

In 3.12.0, there will be a warning (off by default) for when you give
an _ as argument to a constant constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.