Skip to content

Deriving a class via an instance that has a TypeError constraint using standalone deriving fails during compilation.

This bug occurs if I define an instance for a typeclass adding a TypeError constraint on the instance, and then I try to derive that instance using Deriving Via in combination with StandaloneDeriving. This is the shortest example I was able to come up with:

{-# Language DataKinds, UndecidableInstances, StandaloneDeriving, DerivingVia #-}  

import GHC.TypeLits

newtype NotNum a = NotNum a

instance (TypeError (Text "Not a num")) => Num (NotNum a) where

data Foo = Foo
deriving via (NotNum Foo) instance Num Foo

In this case, it'll fail in compilation with 'Not a Num'.

This only seems to happen when combining deriving via with standalone deriving, because if I derive the class like:

data Foo = Foo deriving Num via (NotNum Foo)

It works as expected (doesn't fail with my custom error until I actually try to use a Foo where I should use a Num)

Trac metadata
Trac field Value
Version 8.6.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information