Opened 12 months ago

Last modified 8 months ago

#15712 new bug

GHC panic with -XDerivingVia

Reported by: Iceland_jack Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.6.1
Keywords: DerivingVia Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by Iceland_jack)

I slipped up and typed Codensity GEndo instead of Codensity (GEndo m), resulting in a GHC panic

{-# Language RankNTypes  #-}
{-# Language DerivingVia #-}

import Control.Monad.Codensity
import Data.Kind

newtype GEndo m a = GEndo (m a -> m a)

newtype LogicT m a = LogicT { runLogicT :: forall xx. (a -> (m xx -> m xx)) -> (m xx -> m xx) }
  deriving 
    (Functor, Applicative, Monad)
  via
    (Codensity GEndo)
$ ghci -ignore-dot-ghci 476.hs
GHCi, version 8.7.20180828: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( 476.hs, interpreted )
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.7.20180828 for x86_64-unknown-linux):
	ASSERT failed!
  Type-correct unfilled coercion hole {co_a2aG}
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
        pprPanic, called at compiler/utils/Outputable.hs:1219:5 in ghc:Outputable
        assertPprPanic, called at compiler/typecheck/TcHsSyn.hs:1716:99 in ghc:TcHsSyn

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

> 

Deriving via Codensity (GEndo m) works as expected.

Change History (3)

comment:1 Changed 12 months ago by Iceland_jack

Description: modified (diff)

comment:2 Changed 12 months ago by Iceland_jack

This is without the https://hackage.haskell.org/package/kan-extensions-5.2/docs/Control-Monad-Codensity.html dependency

{-# Language RankNTypes    #-}
{-# Language DerivingVia   #-}
{-# Language DeriveFunctor #-}

-- import Control.Monad.Codensity
import Data.Kind

newtype Codensity f a = Codensity (forall xx. (a -> f xx) -> f xx)
  deriving 
    (Functor)

newtype GEndo m a = GEndo (m a -> m a)

newtype LogicT m a = LogicT (forall xx. (a -> (m xx -> m xx)) -> (m xx -> m xx))
  deriving 
    (Functor)
  via
    (Codensity GEndo)
Last edited 12 months ago by Iceland_jack (previous) (diff)

comment:3 Changed 8 months ago by simonpj

With HEAD, and GHC 8.6, for the code in comment:2 I get

T15712.hs:20:16: error:
    • Expecting one more argument to ‘GEndo’
      Expected kind ‘* -> *’, but ‘GEndo’ has kind ‘(* -> *) -> * -> *’
    • In the first argument of ‘Codensity’, namely ‘GEndo’
      In the newtype declaration for ‘LogicT’
   |
20 |     (Codensity GEndo)
   |                ^^^^^

Can others confirm? If so, could someone add a regression test and close? Thanks!

Note: See TracTickets for help on using tickets.