DerivingVia: incorrectly accepts deriving via types with differing runtime representations
Summary
GHC can accept a deriving via
clause for two types which are not Coercible
when the class being derived's methods are Coercible
Steps to reproduce
example MRE
{-# LANGUAGE
DerivingVia
, TypeApplications
#-}
module Main where
import Data.Proxy
class Tag a where
tag :: Proxy a -> Int
data Foo = Foo Int
instance Tag Foo where
tag _ = 0
data Bar = Bar Char | Bar2 Bool
deriving Tag via Foo
main :: IO ()
main = do
print $ tag $ Proxy @Foo
print $ tag $ Proxy @Bar
Expected behavior
GHC should reject this program, since Foo
and Bar
don't have equal runtime representation.
Environment
- GHC version used: 8.10.2
- Operating System: Arch Linux 5.9.13-arch1-1
- System Architecture: x86_64