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

Unused value warning on a recursive value that is used #7429

Closed
vicuna opened this issue Dec 7, 2016 · 5 comments
Closed

Unused value warning on a recursive value that is used #7429

vicuna opened this issue Dec 7, 2016 · 5 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Dec 7, 2016

Original bug ID: 7429
Reporter: @lpw25
Assigned to: @lpw25
Status: resolved (set by @lpw25 on 2016-12-07T16:12:59Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 4.04.0
Category: typing
Related to: #6738
Monitored by: @gasche

Bug description

The following code:

let rec x = lazy (subscribe (fun _ -> (Lazy.force x)));;

produces an unused value warning for x if it is not used in the rest of the program. However, the binding to x is required in this case.

Obviously, the warning is trying to make sure that things like recursive function definitions do not get automatically marked as used just because they are recursive, but it seems that the issue is subtler than how the current check works.

This code is pretty unusual, and the work-around is easy (simply rename x to _x) so it may not be worth fixing if the criteria is too complicated.

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @alainfrisch

the work-around is easy

Another workaround is to remove the useless declaration altogether, no?

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @lpw25

The point is that the declaration is not useless. The subscribe function is side-effecting and returns a value that we wish to use inside the function passed to subscribe.

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @alainfrisch

But how is 'subscribe' being executed if 'x' is not forced?

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @lpw25

Oh wait, my example is actually useless. I'll have another look at the original code it comes from and see if it can be made into a sensible example.

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @lpw25

Ok, I've had a look at the original code and it seems that it would not compile. It was equivalent to:

let rec x = subscribe (fun _ -> x);;

The confusion seems to have come from the fact that you get the warning about it being unused before you get the error about it not compiling.

So basically the warning is overly aggressive, but only on programs that are inappropriately recursive. In which case, this bug report is just a duplicate of the general complaint that recursion errors are handled after type-checking.

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

2 participants