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

Quirk of the type-checker: a strange disappearance of warning 20 (unused argument) #6660

Closed
vicuna opened this issue Nov 17, 2014 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Nov 17, 2014

Original bug ID: 6660
Reporter: bvaugon
Assigned to: @garrigue
Status: acknowledged (set by @garrigue on 2014-12-08T08:30:03Z)
Resolution: open
Priority: normal
Severity: feature
Version: 4.02.1
Target version: undecided
Category: typing
Monitored by: @ygrek @hcarty

Bug description

Considering the following (classical) definition of fail:

# let fail fmt = Printf.ksprintf failwith fmt;;

the following call is wrongly type-checked without any warning:

# fail "error" 123;;

(***)

However, the type-checking of the code:

# (fail "error") 123;;
Warning 20: this argument will not be used by the function.

rightly raises a warning 20 on the argument 123. Thanks to this message,
the programmer understand that he simply forgot a "%d" in his format.

(***)

Remarks that the type-checker behaviour is strange on this kind
of thing, since the code:

# failwith "hahaha" 123;;
Warning 20: this argument will not be used by the function.

rightly raises a warning.

(***)

Since this kind of programming error may happen quickly, it would be
interesting that the warning 20 be raised even when all the arguments
are passed at once (in this kind of configuration).

From a more general point of view, it would be more intuitive that the
OCaml type checker verifies the property:
(f x y) is correctly typed iff ((f x) y) is correctly typed

Steps to reproduce

# let fail fmt = Printf.ksprintf failwith fmt;;
# fail "error" 123;;
@vicuna
Copy link
Author

vicuna commented Dec 8, 2014

Comment author: @garrigue

This warning doesn't try to be complete: it couldn't anyway, since there is no way to know whether an argument will really be used or not.
Here the problem is a consequence of the way application works in ocaml. In particular, the property
(f x y) is correctly typed iff ((f x) y) is correctly typed
is actually false, because the type systems handles x and y in a symmetric way in the first case, and an asymmetric way in the second case.

For instance, assuming
let f ?(a=0) x y = a+x+y
then
(f 1 2 ~a:3)
is valid, but
((f 1) 2 ~a:3)
is not.

@github-actions
Copy link

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 11, 2020
@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