Skip to content

GHC panic when compiling unsafeCoerce

The GHC compiler crashes on the following program.

module Test where

import Unsafe.Coerce
import Graphics.Rendering.OpenGL (color, Color3, GLdouble)

data D4 = D4 Double Double Double Double

crash :: D4 -> IO ()
crash c = color (invalidCast c)

invalidCast :: D4 -> Color3 GLdouble
invalidCast = unsafeCoerce

With the following output:

[1 of 1] Compiling Test             ( Test.hs, Test.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 7.6.1 for x86_64-apple-darwin):
	cgLookupPanic (probably invalid Core; try -dcore-lint)
    ww_s28U{v} [lid]
    static binds for:
    local binds for:

I've made several attempts to make the input program smaller, but all modifications will result in successful compilation.

The cast is invalid but should produce an runtime error, not a compile time error.

Changes I made that somehow prevent this bug from appearing:

  • Changing the crash functions into point free style color . invalidCast.
  • Decreasing the amount of doubles in the D4 datatype.
  • Inlining the exact definitions from the OpenGL package.
  • Using the print function instead of the color function.

(btw, I know I shouldn't use unsafeCoerce)

Trac metadata
Trac field Value
Version 7.6.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information