[commit: ghc] master: Fix errors caused by invalid candidates leaking from hole fits (39de4e3)

git at git.haskell.org git at git.haskell.org
Wed Jul 4 12:48:21 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/39de4e3d33dd9879398062620ad00b1e3b8481ce/ghc

>---------------------------------------------------------------

commit 39de4e3d33dd9879398062620ad00b1e3b8481ce
Author: Matthías Páll Gissurarson <mpg at mpg.is>
Date:   Wed Jul 4 14:54:54 2018 +0300

    Fix errors caused by invalid candidates leaking from hole fits
    
    This is a one line fix (and a note) that fixes four tickets, #15007,
     #15321 and #15202, #15314
    
    The issue was that errors caused by illegal candidates (according to GHC
    stage or being internal names) were leaking to the user, causing
    bewildering error messages. If a candidate causes the type checker to
    error, it is not a valid hole fit, and should be discarded.
    
    As mentioned in #15321, this can cause a pattern of omissions, which
    might be hard to discover. A better approach would be to gather the
    error messages, and ask users to report them as GHC bugs. This will be
    implemented in a subsequent change.
    
    Reviewers: bgamari, simonpj
    
    Reviewed By: simonpj
    
    Subscribers: simonpj, rwbarton, thomie, carter
    
    GHC Trac Issues: #15007, #15321, #15202, #15314
    
    Differential Revision: https://phabricator.haskell.org/D4909


>---------------------------------------------------------------

39de4e3d33dd9879398062620ad00b1e3b8481ce
 compiler/typecheck/TcHoleErrors.hs | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/compiler/typecheck/TcHoleErrors.hs b/compiler/typecheck/TcHoleErrors.hs
index e624d00..ee4d617 100644
--- a/compiler/typecheck/TcHoleErrors.hs
+++ b/compiler/typecheck/TcHoleErrors.hs
@@ -355,6 +355,15 @@ the only non-hole constraint that mentions any free type variables mentioned in
 the hole constraint for `_a`, namely `a_a1pd[tau:2]` , and similarly for the
 hole `_b` we only require that the `$dShow_a1pe` constraint is solved.
 
+Note [Leaking errors]
+~~~~~~~~~~~~~~~~~~~
+
+When considering candidates, GHC believes that we're checking for validity in
+actual source. However, As evidenced by #15321, #15007 and #15202, this can
+cause bewildering error messages. The solution here is simple: if a candidate
+would cause the type checker to error, it is not a valid hole fit, and thus it
+is discarded.
+
 -}
 
 
@@ -509,11 +518,11 @@ getLocalBindings tidy_orig ct
 
 -- See Note [Valid hole fits include ...]
 findValidHoleFits :: TidyEnv        --The tidy_env for zonking
-                           -> [Implication]  --Enclosing implications for givens
-                           -> [Ct] -- The  unsolved simple constraints in the
-                                   -- implication for the hole.
-                           -> Ct   -- The hole constraint itself
-                           -> TcM (TidyEnv, SDoc)
+                  -> [Implication]  --Enclosing implications for givens
+                  -> [Ct] -- The  unsolved simple constraints in the
+                          -- implication for the hole.
+                  -> Ct   -- The hole constraint itself
+                  -> TcM (TidyEnv, SDoc)
 findValidHoleFits tidy_env implics simples ct | isExprHoleCt ct =
   do { rdr_env <- getGlobalRdrEnv
      ; lclBinds <- getLocalBindings tidy_env ct
@@ -818,6 +827,8 @@ findValidHoleFits tidy_env implics simples ct | isExprHoleCt ct =
         go subs _ _ _ [] = return (False, reverse subs)
         go subs _ (Just 0) _ _ = return (True, reverse subs)
         go subs seen maxleft ty (el:elts) =
+          -- See Note [Leaking errors]
+          tryTcDiscardingErrs discard_it $
           do { traceTc "lookingUp" $ ppr el
              ; maybeThing <- lookup el
              ; case maybeThing of



More information about the ghc-commits mailing list