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

More partial application warnings #9560

Merged
merged 1 commit into from Jun 2, 2020
Merged

Conversation

stedolan
Copy link
Contributor

@stedolan stedolan commented May 13, 2020

As #7221 points out, warning 5 (on maybe-unintended partial applications) would be useful in more situtations, e.g:

# let f a b = a + b
  let g x = x + 1
  let _ = g (f 1);;
Error: This expression has type int -> int
       but an expression was expected of type int

This patch makes it report this instead:

# let f a b = a + b
    let g x = x + 1
    let _ = g (f 1);;
Warning 5: this function application is partial,
maybe some arguments are missing.
Error: This expression has type int -> int
       but an expression was expected of type int

Concretely, whenever a type_expect fails with a Expr_type_clash on an application which is partial, warning 5 gets reported in addition to the error.

@stedolan stedolan force-pushed the more-partial branch 2 times, most recently from 234bdf4 to 734ccf5 Compare May 13, 2020 12:34
@stedolan
Copy link
Contributor Author

stedolan commented Jun 1, 2020

Any takers for review? This is not a complicated change. (@gasche / @lpw25 / @trefis ?)

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the code and believe it is correct (but see comment below). I am inclined to say that the feature is a good idea, and I trust @stedolan and @whitequark's judgment, but I also know that this is a general area @trefis has given more though about, so he might want to give his opinion as well (if he has time).

try rue exp
with Error (_, _, Expr_type_clash _) as err ->
check_partial_application false exp;
raise err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the patch seems correct, but I worry (slightly) about trashing of backtraces that may occur during check_partial_application (it uses Format, etc.). We could use the get_raw_backtrace / raise_with_backtrace dance to avoid this, but it makes the code much less pleasant. We could almost use Misc.try_finally, but unfortunately its exceptionally clause does not take the exception as an input, so this is not quite possible. My perfectionist self would recommend tweaking try_finally in this way and using it here, or defining a new Misc combinator for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's now a shiny new Misc.reraise_preserving_backtrace

(I consider the behaviour of overwriting the global backtrace to be a bug, hopefully one day we can delete reraise_preserving_backtrace as it will just be how all reraises act)

@trefis
Copy link
Contributor

trefis commented Jun 1, 2020

I'm not sure I have really thought more than anyone else about this. But anyway, I like this proposal :)

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but see my non-trivial code comment.

@gasche
Copy link
Member

gasche commented Jun 2, 2020

Thanks! Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants