Skip to content

mkNewTyConRhs panic when trying to constrain newtype with Coercible

Summary

The following code panics in ghc 8.8.3:

{-# LANGUAGE FlexibleContexts #-}

import Data.Coerce

newtype T = Coercible () T => T ()

Error message:

[1 of 1] Compiling Main             ( abug.hs, abug.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.8.3 for x86_64-unknown-linux):
        mkNewTyConRhs
  T [Coercible () T, ()]
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable
        pprPanic, called at compiler/iface/BuildTyCl.hs:65:27 in ghc:BuildTyCl

This seems to come from whatever is done to infer Coercible's instances. Any other Constraint (weather or not using a multi parameter class) gives an error message:

{-# LANGUAGE FlexibleContexts #-}

newtype T = Show T => T ()

results in:

[1 of 1] Compiling Main             ( abug.hs, abug.o )

abug.hs:3:13: error:
    * A newtype constructor cannot have a context in its type
      T :: Show T => () -> T
    * In the definition of data constructor `T'
      In the newtype declaration for `T'
  |
3 | newtype T = Show T => T ()
  |             ^^^^^^^^^^^^^^

Expected behavior

Should most likely print an error message as in the second example.

Environment

  • GHC version used: 8.8.3
Edited by matzemathics
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information