Commit 22c951e6 authored by Matthías Páll Gissurarson's avatar Matthías Páll Gissurarson Committed by Ben Gamari
Browse files

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:

(cherry picked from commit 39de4e3d)
parent a39b58d5
......@@ -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.
......@@ -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
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