The 'impossible' happens when attempting a particular (and trivial) `DerivingVia`
Summary
When using DerivingVia
, the presence or absence of a particular newtype type constructor in the datatype declaration can cause GHC to issue an error when deriving an instance it clearly should be able to derive.
Steps to reproduce
Minimal reproduction here: https://github.com/friedbrice/deriving-via-bug
Simple Haskell program, should be a correct use of DerivingVia
{-# LANGUAGE DerivingVia #-}
import Control.Monad.Reader (ReaderT (..))
newtype Control m a = Control (ReaderT () m a)
deriving Functor via ReaderT () m
newtype Experiment m a = Experiment (() -> m a)
deriving Functor via ReaderT () m
main :: IO ()
main = pure ()
Attempting to compile results in the following unexpected GHC error.
main.hs:9:35: error:ghc-9.2.7: panic! (the 'impossible' happened)
(GHC version 9.2.7:
No skolem info:
[k_aH3]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Tc/Errors.hs:2948:17 in ghc:GHC.Tc.Errors
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
Expected behavior
I expect the program to compile successfully, and I expect to have the obvious instance Functor m => Functor (Experiment m)
derived through the instance Functor m => Functor (ReaderT r m)
.
Environment
- GHC version used: 9.2.7
Optional:
- Operating System: Macos
- System Architecture: Arm64