From gitter:
do you mean by default when you do
expr ; expr? If so, then I believe you can accomplish that with the compiler flag called "strict sequence" iirc.
using let () = foo bla warns when the returned value of foo bla isn't unit. Using let _ = foo bla discards the return value, which might not be intended.
@chenglou I believe that doing
let result = {
somethingWithSideEffects ();
200;
};
Will warn if somethingWithSideEffects () doesn't have return type unit (with strict-sequence warning enabled). Would this do what you want in most cases?
FWIW, let _ = ... is the source of a lot of subtle bugs, including hiding unintended partial function application.
@jordwalke yeah that works but I was more thinking about somethingWithSideEffects () by itself, which compiles to let _ = somethingWithSideEffects (). At the top.
I believe strict-sequence warning would work at the top level too.
This would still be very nice to have. Reason's syntax allows for almost script-like top level expressions which can be very useful:
print_endline("Hello world");
but it doesn't complain, even with -strict-sequence enabled, if the expression is does not evaluate to unit:
// This doesn't warn
"Hello world";
so it's easy to let bugs from partial or no application fall through.
For clarification - the small examples in my previous comment exist at the top level of a file/module, not with a let binding.
Would a PR making this change be accepted at this point?
Most helpful comment
FWIW,
let _ = ...is the source of a lot of subtle bugs, including hiding unintended partial function application.