Commit 71c0cc15 authored by thomie's avatar thomie Committed by Ben Gamari

GHCi should not defer typed holes

In the function `tcUserStmt` in compiler/typecheck/TcRnDriver.hs, before
going over the different ways ('plans') to lift an expression typed at
the prompt into the GHCi monad, `Opt_DeferTypeErrors` is disabled. Here is
the accompanying comment:

```
-- Ensure that type errors don't get deferred when type checking the
-- naked expression. Deferring type errors here is unhelpful because the
-- expression gets evaluated right away anyway. It also would potentially
-- emit redundant type-error warnings, one from each plan.
; plan <- unsetGOptM Opt_DeferTypeErrors $
```

Since `Opt_DeferTypeErrors` implies `Opt_DeferTypedHoles`,
`Opt_DeferTypedHoles` should be disabled here as well. This improves
the error message for T10248 (it doesn't mention ghciStepIO anymore).
This is a partial fix for #10249, and a complete fix for #11130.

Depends on D1526

Reviewers: simonpj, austin, bgamari

Reviewed By: simonpj

Subscribers: simonpj

Differential Revision: https://phabricator.haskell.org/D1527

GHC Trac Issues: #10249, #11130
parent 399a5b46
...@@ -1641,7 +1641,8 @@ tcUserStmt (L loc (BodyStmt expr _ _ _)) ...@@ -1641,7 +1641,8 @@ tcUserStmt (L loc (BodyStmt expr _ _ _))
-- naked expression. Deferring type errors here is unhelpful because the -- naked expression. Deferring type errors here is unhelpful because the
-- expression gets evaluated right away anyway. It also would potentially -- expression gets evaluated right away anyway. It also would potentially
-- emit two redundant type-error warnings, one from each plan. -- emit two redundant type-error warnings, one from each plan.
; plan <- unsetGOptM Opt_DeferTypeErrors $ runPlans [ ; plan <- unsetGOptM Opt_DeferTypeErrors $
unsetGOptM Opt_DeferTypedHoles $ runPlans [
-- Plan A -- Plan A
do { stuff@([it_id], _) <- tcGhciStmts [bind_stmt, print_it] do { stuff@([it_id], _) <- tcGhciStmts [bind_stmt, print_it]
; it_ty <- zonkTcType (idType it_id) ; it_ty <- zonkTcType (idType it_id)
......
<interactive>:2:10: warning: <interactive>:2:10: error:
Found hole: _ :: IO () Found hole: _ :: f a
In the second argument of ‘(<$>)’, namely ‘_’ Where: ‘f’ is a rigid type variable bound by
In the first argument of ‘ghciStepIO :: IO a -> IO a’, namely the inferred type of it :: Functor f => f (Maybe a)
‘Just <$> _’ at <interactive>:2:1
In a stmt of an interactive GHCi command: ‘a’ is a rigid type variable bound by
it <- ghciStepIO :: IO a -> IO a (Just <$> _) the inferred type of it :: Functor f => f (Maybe a)
*** Exception: <interactive>:2:10: error: at <interactive>:2:1
Found hole: _ :: IO () In the second argument of ‘(<$>)’, namely ‘_’
In the second argument of ‘(<$>)’, namely ‘_’ In the expression: Just <$> _
In the first argument of ‘ghciStepIO :: IO a -> IO a’, namely In an equation for ‘it’: it = Just <$> _
‘Just <$> _’ Relevant bindings include
In a stmt of an interactive GHCi command: it :: f (Maybe a) (bound at <interactive>:2:1)
it <- ghciStepIO :: IO a -> IO a (Just <$> _)
(deferred type error)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment