Skip to content

GHC 9.2 creates an unsafe coercion between a boxed and an unboxed type

The attached file (a single module with no dependencies, but unfortunately a bit long/complex) causes a Core Lint error on GHC 9.2. Compile with -O1 -dcore-lint.
GHC 9.0 and GHC HEAD both seem to not be affected.

 warning:
    Unsafe coercion: between unboxed and boxed value
      From: ()
        To: Int#

Bug.hs

In the dump-ds-preopt output I am seeing some worrying coercions, e.g.

$d~_a1c4 :: MyInt ~ 'LitTy
[LclId]
$d~_a1c4
  = GHC.Types.Eq#
      @(Type 'KEmpty 'Type)
      @MyInt
      @'LitTy
      @~(<'LitTy>_N :: 'LitTy GHC.Prim.~# 'LitTy)

but here the promoted LitTy constructor is insufficiently applied. It seems that the definition of the promoted data constructor LitTy confuses GHC, as it only takes invisible arguments.

I haven't investigated further or identified which commits broke or fixed this yet. @rae?

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