No skolem info panic on invalid type application (GHC 9+)
Summary
Getting a compiler crash with the message "No skolem info" on a sample snippet where I accidentally used an invalid type application on an expression.
I can confirm the bug does not happen on GHC 8.10.7. I tested it on GHC 9.2.1 and GHC 9.2.2 - the bug persists in both. I have not checked in 9.0.1.
Steps to reproduce
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
module Main where
import Generics.SOP
import Generics.SOP.NP (ana_NP)
-- | [0..n] but for NP and the `n` is derived from `xs`.
rangeNP :: All Top xs => NP (K Int) xs
rangeNP = ana_NP f (K 0)
where
f :: K Int (y : ys) -> (K Int y, K Int ys)
f (K i) = (K i, K $ i + 1)
fieldNames :: forall a flds. (HasDatatypeInfo a, IsProductType a flds) => NP (K String) flds
fieldNames = case hd . constructorInfo . datatypeInfo $ Proxy @a of
Record _ np -> hmap (K . fieldName) np
-- This branch uses stuff like `--0`, `--1` and so on for argument names.
_ -> hmap undefined rangeNP @flds
Notice that final line, hmap
. It should actually be hmap undefined $ rangeNP @flds
(don't mind the undefined
, I was actually using a typed hole there but didn't want to involve type holes in here).
This produces-
$ cabal build
Build profile: -w ghc-9.2.2 -O1
In order, the following will be built (use -v for more details):
- testHS-0.1.0.0 (exe:testHS) (first run)
Preprocessing executable 'testHS' for testHS-0.1.0.0..
Building executable 'testHS' for testHS-0.1.0.0..
[1 of 1] Compiling Main ( src/Main.hs, /testHS/dist-newstyle/build/x86_64-linux/ghc-9.2.2/testHS-0.1.0.0/x/testHS/build/testHS/testHS-tmp/Main.o )
src/Main.hs:26:39: error:ghc: panic! (the 'impossible' happened)
(GHC version 9.2.2:
No skolem info:
[flds_a73s[sk:1]]
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
Same thing for GHC 9.2.1.
On the other hand, GHC 8.10.7 handles it correctly-
$ cabal build
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
- testHS-0.1.0.0 (exe:testHS) (first run)
Preprocessing executable 'testHS' for testHS-0.1.0.0..
Building executable 'testHS' for testHS-0.1.0.0..
[1 of 1] Compiling Main ( src/Main.hs, /testHS/dist-newstyle/build/x86_64-linux/ghc-8.10.7/testHS-0.1.0.0/x/testHS/build/testHS/testHS-tmp/Main.o )
src/Main.hs:28:8: error:
• Cannot apply expression of type ‘NP f'0 xs0’
to a visible type argument ‘flds’
• In the expression: hmap undefined rangeNP @flds
In a case alternative: _ -> hmap undefined rangeNP @flds
In the expression:
case hd . constructorInfo . datatypeInfo $ Proxy @a of
Record _ np -> hmap (K . fieldName) np
_ -> hmap undefined rangeNP @flds
|
28 | _ -> hmap undefined rangeNP @flds
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Which is indeed true.
Expected behavior
No crash, ideally. Would like same behavior as GHC 8.10.7.
Environment
- GHC version used: 9.2.1, 9.2.2
Does not happen on GHC 8.10.7.
I'm using generics-sop == 0.5.1.2
, though I doubt it's directly related to generics-sop. I haven't managed to get a simpler (no dependencies) reproduction yet, sorry.
Optional:
- Operating System: Arch linux
- System Architecture: 5.17.1-arch1-1 x86_64 GNU/Linux