Skip to content

Type error recovery crash

This program is derived from #16376 (closed):

{-# LANGUAGE TypeApplications #-}
module Bug where

h x = let f = id @Maybe
      in Just f

If you compile with -fdefer-type-errors -dcore-lint you'll get

*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
    In the expression: f_arZ @ a_at1
    Out of scope: f_arZ :: forall a. a
                  [LclId]
*** Offending Program ***
Rec {
$trModule :: Module
[LclIdX]
$trModule = Module (TrNameS "main"#) (TrNameS "T16376"#)

h :: forall p a. p -> Maybe a
[LclIdX]
h = \ (@ p_asV) (@ a_at1) ->
      case typeError
             @ ('TupleRep '[])
             @ ((* -> *) ~# *)
             "T16376.hs:4:19: error:\n\
             \    \\226\\128\\162 Expecting one more argument to \\226\\128\\152Maybe\\226\\128\\153\n\
             \      Expected a type, but \\226\\128\\152Maybe\\226\\128\\153 has kind \\226\\128\\152* -> *\\226\\128\\153\n\
             \    \\226\\128\\162 In the type \\226\\128\\152Maybe\\226\\128\\153\n\
             \      In the expression: id @Maybe\n\
             \      In an equation for \\226\\128\\152f\\226\\128\\153: f = id @Maybe\n\
             \(deferred type error)"#
      of co_asZ
      { __DEFAULT ->
      letrec {
        h_at5 :: p_asV -> Maybe a_at1
        [LclId]
        h_at5 = \ (x_arY :: p_asV) -> Just @ a_at1 (f_arZ @ a_at1); } in
      h_at5
      }
end Rec }

Without Lint it just squeezes by, because that `case typeError of ..." discards the "..." since it is unreachable

Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information