Skip to content

Core Lint failure in list comprehension on -O0 with coercion optimisation

The following program causes a Core Lint failure on GHC HEAD with -O0:

type R :: Type -> RuntimeRep
type family R a where
  R () = LiftedRep

type C :: Type -> Constraint
class C a where
  type T a :: TYPE (R a)
  foo :: () -> T a

instance C () where
  type T () = Int
  foo _ = head $ [ a | a <- [ 12345 ] ]
*** Core Lint errors : in result of Simplifier ***
testsuite\tests\typecheck\should_compile\T21205.hs:23:10: warning:
    From-type of Cast differs from type of enclosed expression
    From-type: () -> T ()
    Type of enclosed expression: () -> (T () |> (TYPE (D:R:R[0]))_N)
    Actual enclosed expression: $cfoo_sXK
    Coercion used in cast: Sym (N:C[0] <()>_N)
    In the RHS of $fC() :: C ()

Removing the $ on the last line makes the problem go away, and so does turning off coercion optimisation with -fno-opt-coercion.

GHC 9.2.1 and before do not seem to be affected, but GHC 9.2.2 does seem to have this bug.

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