Commit aab92412 authored by Simon Peyton Jones's avatar Simon Peyton Jones Committed by Ben Gamari

Adjust error check for class method types

Fixes Trac #11793.  Nothing deep here.

(cherry picked from commit e24b3b1e)
parent f8b467d6
......@@ -2380,9 +2380,12 @@ checkValidClass cls
(_,theta2,_) = tcSplitSigmaTy tau1
check_constraint :: TcPredType -> TcM ()
check_constraint pred
= when (tyCoVarsOfType pred `subVarSet` cls_tv_set)
check_constraint pred -- See Note [Class method constraints]
= when (not (isEmptyVarSet pred_tvs) &&
pred_tvs `subVarSet` cls_tv_set)
(addErrTc (badMethPred sel_id pred))
pred_tvs = tyCoVarsOfType pred
check_at (ATI fam_tc m_dflt_rhs)
= do { checkTc (cls_arity == 0 || any (`elemVarSet` cls_tv_set) fam_tvs)
......@@ -2421,7 +2424,21 @@ checkFamFlag tc_name
err_msg = hang (text "Illegal family declaration for" <+> quotes (ppr tc_name))
2 (text "Use TypeFamilies to allow indexed type families")
{- Note [Class method constraints]
Haskell 2010 is supposed to reject
class C a where
op :: Eq a => a -> a
where the method type costrains only the class variable(s). (The extension
-XConstrainedClassMethods switches off this check.) But regardless
we should not reject
class C a where
op :: (?x::Int) => a -> a
as pointed out in Trac #11793. So the test here rejects the program if
* -XConstrainedClassMethods is off
* the tyvars of the constraint are non-empty
* all the tyvars are class tyvars, none are locally quantified
Note [Abort when superclass cycle is detected]
We must avoid doing the ambiguity check for the methods (in
{-# LANGUAGE ImplicitParams #-}
module T11793 where
class C a where
op :: (?x::Int) => a -> a
-- Should be OK even without ConstrainedClassMethods
......@@ -510,3 +510,4 @@ test('T11699', normal, compile, [''])
test('T11512', normal, compile, [''])
test('T11754', normal, compile, [''])
test('T11811', normal, compile, [''])
test('T11793', normal, compile, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment