Regression with TypeErrors in 9.4.1-alpha1
Summary
I encountered this while trying to build servant
with GHC-9.4.1-alpha1 and managed to extract the following independent reproducer.
Steps to reproduce
Try to compile the following program:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE Haskell2010 #-}
import Data.Kind
import GHC.TypeLits
type NoInstanceForSub (tycls :: k) (expr :: k') =
Text "There is no instance for " :<>: ShowType tycls
:<>: Text " (" :<>: ShowType expr :<>: Text " :> ...)"
class Foo a
instance TypeError (NoInstanceForSub Foo ty) => Foo ty
main :: IO ()
main = pure ()
You will get the following error:
Test.hs:19:10: error:
• There is no instance for Foo (ty :> ...)
• In the ambiguity check for an instance declaration
In the instance declaration for ‘Foo ty’
|
19 | instance TypeError (NoInstanceForSub Foo ty) => Foo ty
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expected behavior
This should compile without error.
Environment
- GHC version used: GHC-9.4.1-alpha1
Observation
The following program compiles fine (we change k
to * -> Constraint
), but this change cannot be applied to servant as there we want to be polymorphic in the kind. Using type applications at use sites does work though:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE Haskell2010 #-}
import Data.Kind
import GHC.TypeLits
type NoInstanceForSub (tycls :: * -> Constraint) (expr :: k') =
Text "There is no instance for " :<>: ShowType tycls
:<>: Text " (" :<>: ShowType expr :<>: Text " :> ...)"
class Foo a
instance TypeError (NoInstanceForSub Foo ty) => Foo ty
main :: IO ()
main = pure ()