DerivingError constraint failures are too lazy
Summary
Constraints on instances derived using DerivingVia
aren't checked eagerly enough.
Steps to reproduce
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DataKinds #-}
import GHC.TypeLits
class Crumb a
newtype Fool a = Fool a
instance TypeError ('Text "You can't do that") => Crumb (Fool a)
deriving via Fool Int
instance Crumb Int
This compiles with no warnings or errors.
Expected behavior
I expect the above program to be rejected, since it produces an instance for Crumb Int
with no constraints when the ground instance it's based on has an unsatisfiable constraint. I don't think this is a soundness problem per se, but it does make me slightly nervous.
This example is a highly boring reduction of a more interesting one in linear-generics
. I'd like to produce a custom type error when attempting to derive an instance of Generics.Linear.Generic1
via Generics.Linear.Unsafe.ViaGHCGenerics.GHCGenerically1
. This sort of works, but only because the derived methods fail to typecheck. Since there are two methods, we get two type errors. And since the errors are on the methods, they end up being considerably more confusing to read than they should be.
Environment
- GHC version used: 9.6.1
Optional:
- Operating System:
- System Architecture: