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

Warning 27 shouldn't trigger on optional argument names #7282

Closed
vicuna opened this issue Jul 1, 2016 · 6 comments
Closed

Warning 27 shouldn't trigger on optional argument names #7282

vicuna opened this issue Jul 1, 2016 · 6 comments
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Jul 1, 2016

Original bug ID: 7282
Reporter: @dra27
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2017-09-24T15:33:03Z)
Resolution: not a bug
Priority: normal
Severity: tweak
Version: 3.09.0
Category: ~DO NOT USE (was: OCaml general)

Bug description

Warning 27 triggers on an optional argument if the variable isn't used in the code. The warning either shouldn't trigger, or should have a separate number.

Steps to reproduce

let foo ?bar () = ()
in
f ()

$ ocamlc -w +27 foo.ml

File "foo.ml", line 1, characters 9-12:
Warning 27: unused variable bar.

Additional information

This is a nuisance when writing functions designed to match a module type. In all (?) other cases, there is a syntax for working around this (e.g. prefixing with _ or just using the wildcard character)

@vicuna
Copy link
Author

vicuna commented Jul 1, 2016

Comment author: @dra27

3.09.0 is where it was introduced, not the version I'm using!

@vicuna
Copy link
Author

vicuna commented Jul 1, 2016

Comment author: @alainfrisch

What's wrong with:

let foo ?bar:_ () = () in ...

?

@vicuna
Copy link
Author

vicuna commented Jul 1, 2016

Comment author: @dra27

Nothing! But where's it documented??? It should be probably be mentioned in Chapter 4? I didn't even know that syntax was available!

Could the text of Warning 27 be customised in this particular instance? It's not really a variable?

@vicuna
Copy link
Author

vicuna commented Jul 1, 2016

Comment author: @gasche

It is documented in a way that could be clarified:

When you want to use distinct names for the variable
and the label appearing in the type, you can use
a naming label of the form ~name:. This also applies
when the argument is not a variable.

let f ~x:x1 ~y:y1 = x1 - y1;;

val f : x:int -> y:int -> int =

We should explicitate that any pattern can be used, and in particular that _ (or a variable name of the form _bar) can be used to ignore the variable.

I'm afraid it may be difficult, from an implementation point of view, to specialize the warning text -- but I would support doing so.

TODO: add information to the manual.

@vicuna
Copy link
Author

vicuna commented Jul 1, 2016

Comment author: @alainfrisch

The actual "reference" documentation is:

http://caml.inria.fr/pub/docs/manual-ocaml/expr.html#parameter

and:

The parameter patterns ~lab and ~(lab [: typ]) are shorthands for respectively ~lab: lab and ~lab:( lab [: typ]), and similarly for their optional counterparts.

@vicuna
Copy link
Author

vicuna commented Jul 1, 2016

Comment author: @gasche

Indeed; dra mentioned Chapter 4, which is the tutorial part of label and variants, and it is the one that could become more informative. The reference part is fine, but in its usual cold-hearted way.

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