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

Pattern matching allows wildcards to be used with nullary constructors #5502

Closed
vicuna opened this issue Feb 8, 2012 · 2 comments
Closed
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Feb 8, 2012

Original bug ID: 5502
Reporter: john_nowak
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2013-08-31T10:46:28Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 3.12.1
Category: ~DO NOT USE (was: OCaml general)

Bug description

The following should most likely be rejected but are accepted by the compiler:

fun (None _) -> 42
match None with None _ -> 42
...

This bug appears to only be present with wildcards; all other pattern arguments to nullary constructors result in the appropriate error.

@vicuna
Copy link
Author

vicuna commented Feb 8, 2012

Comment author: john_nowak

I should note that this is actually a minor portability issue. Older OCaml compilers (e.g. 3.10.2) will reject such code.

@vicuna
Copy link
Author

vicuna commented Feb 9, 2012

Comment author: @gasche

This is not a bug but a dubious feature. This behavior is intentional: Foo _ will ignore the constructor at any arity (including zero). This is so you don't have to write eg. Foo (_, _, _, _) if the arity is four, which would be rather painful.

PS: but you can ask to be warned in the case where this construct is used on a constant constructor (arity zero): it's warning 28, introduced in 3.12.0.

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