diff options
author | Krzysztof Gogolewski <krzysztof.gogolewski@tweag.io> | 2021-07-27 16:52:52 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-08-04 01:33:03 -0400 |
commit | 2c714f07f4ab6823de50aaa4947e86326799f44f (patch) | |
tree | b2fcf0005c23adc062b1ddd9e814aa743450cec9 /compiler/GHC/Tc/Errors.hs | |
parent | 4f6726779fa3cbbfe97de49b1d26d5a665c74840 (diff) | |
download | haskell-2c714f07f4ab6823de50aaa4947e86326799f44f.tar.gz |
Disable -fdefer-type-errors for linear types (#20083)
Diffstat (limited to 'compiler/GHC/Tc/Errors.hs')
-rw-r--r-- | compiler/GHC/Tc/Errors.hs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/compiler/GHC/Tc/Errors.hs b/compiler/GHC/Tc/Errors.hs index a504fd44ea..dc95a6a81d 100644 --- a/compiler/GHC/Tc/Errors.hs +++ b/compiler/GHC/Tc/Errors.hs @@ -926,10 +926,18 @@ suppressGroup mk_err ctxt cts ; traceTc "Suppressing errors for" (ppr cts) ; mapM_ (addDeferredBinding ctxt err) cts } +-- See Note [No deferring for multiplicity errors] +nonDeferrableOrigin :: CtOrigin -> Bool +nonDeferrableOrigin NonLinearPatternOrigin = True +nonDeferrableOrigin (UsageEnvironmentOf _) = True +nonDeferrableOrigin _ = False + maybeReportError :: ReportErrCtxt -> Ct -> Report -> TcM () maybeReportError ctxt ct report = unless (cec_suppress ctxt) $ -- Some worse error has occurred, so suppress this diagnostic - do let reason = cec_defer_type_errors ctxt + do let reason | nonDeferrableOrigin (ctOrigin ct) = ErrorWithoutFlag + | otherwise = cec_defer_type_errors ctxt + -- See Note [No deferring for multiplicity errors] msg <- mkErrorReport reason ctxt (ctLocEnv (ctLoc ct)) report reportDiagnostic msg @@ -1087,6 +1095,27 @@ is perhaps a bit *over*-consistent! With #10283, you can now opt out of deferred type error warnings. +Note [No deferring for multiplicity errors] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +As explained in Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify, +linear types do not support casts and any nontrivial coercion will raise +an error during desugaring. + +This means that even if we defer a multiplicity mismatch during typechecking, +the desugarer will refuse to compile anyway. Worse: the error raised +by the desugarer would shadow the type mismatch warnings (#20083). +As a solution, we refuse to defer submultiplicity constraints. Test: T20083. + +To determine whether a constraint arose from a submultiplicity check, we +look at the CtOrigin. All calls to tcSubMult use one of two origins, +UsageEnvironmentOf and NonLinearPatternOrigin. Those origins are not +used outside of linear types. + +In the future, we should compile 'WpMultCoercion' to a runtime error with +-fdefer-type-errors, but the current implementation does not always +place the wrapper in the right place and the resulting program can fail Lint. +This plan is tracked in #20083. + Note [Deferred errors for coercion holes] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Suppose we need to defer a type error where the destination for the evidence |