Skip to content

GHC 9.4.5, 9.6.1: Fails to differentiate between Constraint and Type when checking for instance overlap

Summary

GHC since 9.4 apparently fails to differentiate instances between kinds Type and Constraint when checking for overlap.

Steps to reproduce

{-# LANGUAGE PolyKinds, FlexibleInstances #-}

module Lib where

import Data.Kind

class Foo (a :: k) where
  bar :: proxy a -> ()

instance Foo (a :: Type) where
  bar = undefined

instance Foo (a :: Constraint) where
  bar = undefined

test :: proxy (k :: Constraint) -> ()
test = bar -- Overlapping instances for Foo k arising from a use of ‘bar’

test2 :: proxy (k :: Type) -> ()
test2 = bar -- Overlapping instances for Foo k arising from a use of ‘bar’

Compiles fine on GHC 9.2.7, fails on GHC 9.4.5 and 9.6.1.

The instance choice should be unambiguous, as arguments are of different kinds. But GHC doesn't see that.

FWIW, it's still able to differentiate between Type and data kinds.

Expected behavior

To compile.

Environment

  • GHC version used: 9.4.5, 9.6.1

Optional:

  • Operating System: Linux
  • System Architecture: amd64
Edited by lierdakil
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information