Skip to content

REPL no skolem info panic in 9.2.4 but all good in 8.10.7 and 9.4.2.

Summary

A module that loads in the REPL with ghc-8.10.7, panics ghc-9.2.4 but loads again in ghc-9.4.2.

Steps to reproduce

The minimal reproduction below errors whereas the original package compiles fine in ghc-8.10.7. Sorry about that. Nevertheless, for ghc-9.2.4 this gutted version still panics so I hope this will be useful.

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE StandaloneDeriving #-}
module AcmeJson where

import Data.Coerce
import Data.Data
import Data.Kind

-- Start of snippet from aeson
newtype AesonKey = AsonKey { unKey :: String }
  deriving (Eq, Ord, Typeable, Data)
data JSONPathElement = Key AesonKey
                     | Index {-# UNPACK #-} !Int
                       deriving (Eq, Ord)
type JSONPath = [JSONPathElement]
type Failure f r = JSONPath -> String -> f r
type Success a f r = a -> f r
data Parser a = Parser {
      runParser :: forall f r.
                   JSONPath
                -> Failure f r
                -> Success a f r
                -> f r
    }
data Value = Object
class FromJSON a where
  parseJSON :: Value -> Parser a
-- End of snippet from aeson

class AcmeJson a where

newtype ViaAcmeJson a = ViaAcmeJson a
newtype ViaTypeAliasAcmeJson n o = ViaTypeAliasAcmeJson n

deriving via ViaAcmeJson (ViaTypeAliasAcmeJson n o) instance
  (AcmeJson o, Coercible o n, Typeable n) => FromJSON (ViaTypeAliasAcmeJson n o)

This is the bad behavior:

> ghc-9.2.4 --interactive AcmeJson.hs
GHCi, version 9.2.4: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling AcmeJson         ( AcmeJson.hs, interpreted )

AcmeJson.hs:39:28: error:ghc: panic! (the 'impossible' happened)
  (GHC version 9.2.4:
	No skolem info:
  [k_a1sL]
  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:2912:17 in ghc:GHC.Tc.Errors

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

Both ghc-8.10.7 and ghc-9.4.2 report errors in the code but GHC itself doesn't panic:

> ghc-8.10.7 --interactive AcmeJson.hs
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling AcmeJson         ( AcmeJson.hs, interpreted )

AcmeJson.hs:38:1: error:
    • Could not deduce (FromJSON
                          (ViaAcmeJson (ViaTypeAliasAcmeJson n o)))
        arising from a use of ‘parseJSON’
      from the context: (AcmeJson o, Coercible o n, Typeable n)
        bound by the instance declaration at AcmeJson.hs:(38,1)-(39,80)
    • In the third argument of ‘coerce’, namely
        ‘(parseJSON @(ViaAcmeJson (ViaTypeAliasAcmeJson n o)))’
      In the expression:
          coerce
            @(Value -> Parser (ViaAcmeJson (ViaTypeAliasAcmeJson n o)))
            @(Value -> Parser (ViaTypeAliasAcmeJson n o))
            (parseJSON @(ViaAcmeJson (ViaTypeAliasAcmeJson n o))) ::
            Value -> Parser (ViaTypeAliasAcmeJson n o)
      In an equation for ‘parseJSON’:
          parseJSON
            = coerce
                @(Value -> Parser (ViaAcmeJson (ViaTypeAliasAcmeJson n o)))
                @(Value -> Parser (ViaTypeAliasAcmeJson n o))
                (parseJSON @(ViaAcmeJson (ViaTypeAliasAcmeJson n o))) ::
                Value -> Parser (ViaTypeAliasAcmeJson n o)
      When typechecking the code for ‘parseJSON’
        in a derived instance for ‘FromJSON (ViaTypeAliasAcmeJson n o)’:
        To see the code I am typechecking, use -ddump-deriv
   |
38 | deriving via ViaAcmeJson (ViaTypeAliasAcmeJson n o) instance
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
Failed, no modules loaded.
> ghc-9.4.2 --interactive AcmeJson.hs
GHCi, version 9.4.2: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling AcmeJson         ( AcmeJson.hs, interpreted )

AcmeJson.hs:39:28: error:
    • Expected kind ‘k’, but ‘n’ has kind ‘*’
      ‘k’ is a rigid type variable bound by
        the deriving clause for ‘ViaAcmeJson (ViaTypeAliasAcmeJson n o)’
        at AcmeJson.hs:38:14-51
    • In the second argument of ‘Coercible’, namely ‘n’
      In the stand-alone deriving instance for
        ‘(AcmeJson o, Coercible o n, Typeable n) =>
         FromJSON (ViaTypeAliasAcmeJson n o)’
   |
39 |   (AcmeJson o, Coercible o n, Typeable n) => FromJSON (ViaTypeAliasAcmeJson n o)
   |                            ^
Failed, no modules loaded.

Expected behavior

That ghc-9.2.4 behaves more like its older and younger sibling versions.

Environment

  • GHC version used: ghc-9.2.4 installed via ghcup

Optional:

  • Operating System: ubuntu 22.04
  • System Architecture: x64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information