Reason: transform `foo bla;` into `let () = ...` rather than `let _ = ...`

Created on 7 Sep 2016  路  7Comments  路  Source: reasonml/reason

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.

FEATURE REQUEST Parser

Most helpful comment

FWIW, let _ = ... is the source of a lot of subtle bugs, including hiding unintended partial function application.

All 7 comments

@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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rickyvetter picture rickyvetter  路  4Comments

modlfo picture modlfo  路  4Comments

rickyvetter picture rickyvetter  路  3Comments

kyldvs picture kyldvs  路  3Comments

chenglou picture chenglou  路  3Comments