Skip to content

Allow `return` in more cases in ApplicativeDo

Ziyang Liu requested to merge zliu41/ghc:ado2 into master

The doc says that the last statement of an ado-block can be one of return E, return $ E, pure E and pure $ E. But return is not accepted in a few cases such as:

-- The ado-block only has one statement
x :: F ()
x = do
  return ()

-- The ado-block only has let-statements besides the `return`
y :: F ()
y = do
  let a = True
  return ()

These currently require Monad instances. This MR fixes it. Normally return is accepted as the last statement because it is stripped in constructing an ApplicativeStmt, but this cannot be done in the above cases, so instead we replace return by pure.

A similar but different issue (when the ado-block contains BindStmt or BodyStmt, the second last statement cannot be LetStmt, even if the last statement uses pure) is fixed in !6786 (closed).

Fixes #20540 (closed)

Merge request reports