Skip to content

Custom type errors in default signatures are reported over-eagerly

Summary

This piece of code triggers a custom type error:

{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}

import GHC.TypeLits


class Foo a where
    foo :: a
    default foo :: TypeError
        (Text "Please define foo manually. Suggested definitions:" :$$:
         Text "  foo = something complicated" :$$:
         Text "  foo = something else complicated")
        => a
    foo = error "unreachable"
default.hs:9:13-15: error: …
    • Please define foo manually. Suggested definitions:
        foo = something complicated
        foo = something else complicated
    • When checking the class method: foo :: forall a. Foo a => a
      In the class declaration for ‘Foo’
  |

Expected behavior

I would expect the type error to be triggered on instance declarations, not the class declaration.

Environment

  • GHC version used: 8.6.5
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information