Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Pattern type constraint in let expression parsed inconsistently #7758
seems to get parsed as
while the expression
which differs only in having parentheses, seems to get parsed as
I would have expected the second parse for both cases. The first parse can be problematic when using PPX, because the variable and expression may need to have different types. In particular, in
foo should have type int, and bar should have type int Lwt.t. See ocsigen/lwt#564.
Steps to reproduce
let () = let foo : int = 42 in let (foo : int) = 42 in ignore foo
Further complicating this in practice is that in 4.05.0, (1) is parsed as
i.e. the constraint is removed from the pattern and appears on the expression only.
Comment author: @Drup
It would be nice to sort this out before the next release, as it messes up with ppx in a way that is difficult to take into account, even with ocaml-migrate-parsetree.
If someone has a concrete proposition on how to make this cleaner, I'm ready to implement it.
Comment author: @alainfrisch
FWIW, I'm not 100% convinced by the proposal, since it would mean treating very differently
let (x1 : t), x2 = e1, e2 in ...
let (x1 : t) = x1 in ...
which might be surprising for ppx authors and for users (in the first case, the annotation would not be propagated to the expression e1).
An alternative would be to keep the annotations only in the pattern at the AST level, but somehow extract them (with a strategy to define) and apply them to the bound expression.