GHC accepts overlapping instances without pragma
The following code is accepted by GHC (I've tested versions 7.6.3, 7.8.4, 7.10.2, ghc 8.0.0.20160204 (rc2) and ghc 7.11.2015121 (git commit 28638dfe)), even though it obviously uses OverlappingInstances (yet the extension is not enabled, nor are any of the new overlappable/ing pragmas used).
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
import Data.Type.Equality
import Data.Proxy
import Debug.Trace
class TypeEq a b where
eqProofClass :: Maybe (a :~: b)
instance TypeEq a b where
eqProofClass = Nothing
instance TypeEq a a where
eqProofClass = Just Refl
data Foo a = Foo a
instance Eq a => Eq (Foo a) where
Foo a1 == Foo a2 = case eqProofClass :: Maybe (a :~: Int) of
Just Refl -> traceShow (a1 :: Int,a2) (a1 == a2)
Nothing -> a1 == (undefined :: a)
main :: IO ()
main = do
print (Foo (1 :: Int) == Foo 2)
putStrLn "--"
print (Foo 'a' == Foo 'b')
{- $output
(1,2)
False
--
False
-}
The example does no longer compiles if I add TypeEq a Int
to the instance context, it then rightfully requests OverlappingInstances
to be enabled.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1-rc2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler (Type checker) |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |