-- | Report error message for equation with injective type variables unused in
-- the RHS. Note [Coverage condition for injective type families], step 6
reportUnusedInjectiveVarsErr :: TyCon
                             -> TyVarSet
                             -> Bool   -- True <=> print invisible arguments
                             -> Bool   -- True <=> suggest -XUndecidableInstances
                             -> CoAxBranch
                             -> TcM ()
reportUnusedInjectiveVarsErr fam_tc tvs has_kinds undec_inst tyfamEqn
  = let (loc, doc) = buildInjectivityError fam_tc
                                  (injectivityErrorHerald $$
                                   herald $$
                                   text "In the type family equation:")
                                  (tyfamEqn :| [])
    in addErrAt loc (pprWithExplicitKindsWhen has_kinds doc)
    where
      herald = sep [ what <+> text "variable" <>
                  pluralVarSet tvs <+> pprVarSet tvs (pprQuotedList . scopedSort)
                , text "cannot be inferred from the right-hand side." ]
               $$ extra

      what | has_kinds = text "Type/kind"
           | otherwise = text "Type"

      extra | undec_inst = text "Using UndecidableInstances might help"
            | otherwise  = empty

-- | Report error message for equation that has a type family call at the top
-- level of RHS
reportUnusedInjectiveVarsErr :: TyCon
                             -> TyVarSet
                             -> Bool   -- True <=> print invisible arguments
                             -> Bool   -- True <=> suggest -XUndecidableInstances
                             -> CoAxBranch
                             -> TcM ()
reportUnusedInjectiveVarsErr fam_tc tvs has_kinds undec_inst tyfamEqn
  = let (loc, doc) = buildInjectivityError fam_tc
                                  (injectivityErrorHerald $$
                                   herald $$
                                   text "In the type family equation:")
                                  (tyfamEqn :| [])
    in addErrAt loc (pprWithExplicitKindsWhen has_kinds doc)
    where
      herald = sep [ what <+> text "variable" <>
                  pluralVarSet tvs <+> pprVarSet tvs (pprQuotedList . scopedSort)
                , text "cannot be inferred from the right-hand side." ]
               $$ extra

      what | has_kinds = text "Type/kind"
           | otherwise = text "Type"

      extra | undec_inst = text "Using UndecidableInstances might help"
            | otherwise  = empty

-- | Report error message for equation that has a type family call at the top
-- level of RHS
reportUnusedInjectiveVarsErr fam_tc tvs has_kinds undec_inst tyfamEqn
  = let (loc, doc) = buildInjectivityError fam_tc
                                  (injectivityErrorHerald $$
                                   herald $$
                                   text "In the type family equation:")
                                  (tyfamEqn :| [])
    in addErrAt loc (pprWithExplicitKindsWhen has_kinds doc)
    where
      herald = sep [ what <+> text "variable" <>
                  pluralVarSet tvs <+> pprVarSet tvs (pprQuotedList . scopedSort)
                , text "cannot be inferred from the right-hand side." ]
               $$ extra

      what | has_kinds = text "Type/kind"
           | otherwise = text "Type"

      extra | undec_inst = text "Using UndecidableInstances might help"
            | otherwise  = empty

-- | Report error message for equation that has a type family call at the top
-- level of RHS