[Git][ghc/ghc][master] Add a safeguard to Core Lint

Marge Bot gitlab at gitlab.haskell.org
Sun Apr 14 12:55:26 UTC 2019



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
e7cad16c by Krzysztof Gogolewski at 2019-04-14T12:49:23Z
Add a safeguard to Core Lint

Lint returns a pair (Maybe a, WarnsAndErrs). The Maybe monad
allows to handle an unrecoverable failure.
In case of such a failure, the error should be added to the second
component of the pair. If this is not done, Lint will silently
accept bad programs. This situation actually happened during
development of linear types. This adds a safeguard.

- - - - -


1 changed file:

- compiler/coreSyn/CoreLint.hs


Changes:

=====================================
compiler/coreSyn/CoreLint.hs
=====================================
@@ -2080,7 +2080,7 @@ defaultLintFlags = LF { lf_check_global_ids = False
 newtype LintM a =
    LintM { unLintM ::
             LintEnv ->
-            WarnsAndErrs ->           -- Error and warning messages so far
+            WarnsAndErrs ->           -- Warning and error messages so far
             (Maybe a, WarnsAndErrs) } -- Result and messages (if any)
 
 type WarnsAndErrs = (Bag MsgDoc, Bag MsgDoc)
@@ -2189,10 +2189,13 @@ data LintLocInfo
   | InCo   Coercion     -- Inside a coercion
 
 initL :: DynFlags -> LintFlags -> InScopeSet
-       -> LintM a -> WarnsAndErrs    -- Errors and warnings
+       -> LintM a -> WarnsAndErrs    -- Warnings and errors
 initL dflags flags in_scope m
   = case unLintM m env (emptyBag, emptyBag) of
-      (_, errs) -> errs
+      (Just _, errs) -> errs
+      (Nothing, errs@(_, e)) | not (isEmptyBag e) -> errs
+                             | otherwise -> pprPanic ("Bug in Lint: a failure occurred " ++
+                                                      "without reporting an error message") empty
   where
     env = LE { le_flags = flags
              , le_subst = mkEmptyTCvSubst in_scope



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/e7cad16c19fb226353d3fb6e92914ed953d32857

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/e7cad16c19fb226353d3fb6e92914ed953d32857
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190414/47c5ece7/attachment-0001.html>


More information about the ghc-commits mailing list