I spent a few hours today debugging a blindingly obvious ignored partial application bug. We would quite like to avoid this in the future and catch it statically. I’m seeking advice on how to catch this with existing warnings and if not seeking opinions on whether it would be a good addition as a new/extended warning?
In our codebase, we rely on unused-var and ignored-partial-application being errors to catch programming mistakes but the following falls through the cracks:
let () =
let f a b = a + b in
let b = f 42 in (* unused-var warning *)
let _ = f 42 in (* ignored-partial-application warning *)
let _a = f 42 in (* neither of the above *)
()
_a
prevents the ignored partial application to be involved as it is a legitimate binding that can be used later. However, because it commonly indicates an ignored variable, it doesn’t trip up unused-var. So us using _a
to be a more descriptive _
prevents us from catching the ignored partial application.
If we could force ignored let bindings to be type annotated, we could also catch this bug. But I don’t think there is a warning to that effect either.
In an ideal world, I’d extend ignored-partial-application
to catch this case, this would be a one liner implementation, but it fails even in the OCaml codebase. If that is not an option, would introducing a new ignored-partial-application-strict
be a better alternative? Or is there some other warning I can use to catch this?