More strict checks over toplevel expressions

We plan to be more strict over toplevel expression, its type has to be unit.

This is a breif summary why we proposed this change:

Note we recently hit another internal issue with partial application. in recent releases we already do a strict check over sequences of expressions: e0 ; e1, it will assume e0 to have type unit. There is a missing place for toplevel phrase

let f =(h,j,()) =>{
  h + j
};

f (1,2);

This partial evaluation warning is not triggered, in upstream, it will trigger a warning if you write let _ = f (1,2).

The root issue is that reason or rescript syntax even easier to write f (a,b..) without writing bindings, shall we enforce that toplevel phrases without bindings should always emit unit type?

What’s the downside of imposing toplevel expression’s type to be unit? Not too much. The toplevel expression’s main use case is REPL which does not apply. The fix would be easy, expression -> ignore and it will work with both old and newer versions of the compiler.

Let me know if there’re some other things I missed, thanks!

2 Likes

This is a great idea. I’ll check if someone has suggested it in upstream too.

To avoid unneeded breaking changes, we introduce a warning 109 (configured as warn-error by default).
The side effect is that it has better error messages https://github.com/rescript-lang/rescript-compiler/pull/4823

3 Likes