Commit e63518f5 authored by Ryan Scott's avatar Ryan Scott

Fix #16116 by removing badAssocRhs

parent 83a22066
...@@ -784,14 +784,6 @@ rnFamInstEqn doc mb_cls rhs_kvars ...@@ -784,14 +784,6 @@ rnFamInstEqn doc mb_cls rhs_kvars
++ map hsLTyVarName bndrs' ++ map hsLTyVarName bndrs'
; warnUnusedTypePatterns all_nms nms_used ; warnUnusedTypePatterns all_nms nms_used
-- See Note [Renaming associated types]
; let bad_tvs = maybe [] (filter is_bad . snd) mb_cls
var_name_set = mkNameSet (map hsLTyVarName bndrs'
++ all_imp_var_names)
is_bad cls_tkv = cls_tkv `elemNameSet` rhs_fvs
&& not (cls_tkv `elemNameSet` var_name_set)
; unless (null bad_tvs) (badAssocRhs bad_tvs)
; return ((bndrs', pats', payload'), rhs_fvs `plusFV` pat_fvs) } ; return ((bndrs', pats', payload'), rhs_fvs `plusFV` pat_fvs) }
; let all_fvs = fvs `addOneFV` unLoc tycon' ; let all_fvs = fvs `addOneFV` unLoc tycon'
...@@ -999,6 +991,21 @@ can all be in scope (Trac #5862): ...@@ -999,6 +991,21 @@ can all be in scope (Trac #5862):
id :: Ob x a => x a a id :: Ob x a => x a a
(.) :: (Ob x a, Ob x b, Ob x c) => x b c -> x a b -> x a c (.) :: (Ob x a, Ob x b, Ob x c) => x b c -> x a b -> x a c
Here 'k' is in scope in the kind signature, just like 'x'. Here 'k' is in scope in the kind signature, just like 'x'.
Although type family equations can bind type variables with explicit foralls,
it need not be the case that all variables that appear on the RHS must be bound
by a forall. For instance, the following is acceptable:
class C a where
type T a b
instance C (Maybe a) where
type forall b. T (Maybe a) b = Either a b
Even though `a` is not bound by the forall, this is still accepted because `a`
was previously bound by the `instance C (Maybe a)` part. (see Trac #16116).
In each case, the function which detects improperly bound variables on the RHS
is TcValidity.checkValidFamPats.
-} -}
...@@ -2078,13 +2085,6 @@ are no data constructors we allow h98_style = True ...@@ -2078,13 +2085,6 @@ are no data constructors we allow h98_style = True
***************************************************** -} ***************************************************** -}
--------------- ---------------
badAssocRhs :: [Name] -> RnM ()
badAssocRhs ns
= addErr (hang (text "The RHS of an associated type declaration mentions"
<+> text "out-of-scope variable" <> plural ns
<+> pprWithCommas (quotes . ppr) ns)
2 (text "All such variables must be bound on the LHS"))
wrongTyFamName :: Name -> Name -> SDoc wrongTyFamName :: Name -> Name -> SDoc
wrongTyFamName fam_tc_name eqn_tc_name wrongTyFamName fam_tc_name eqn_tc_name
= hang (text "Mismatched type name in type family instance.") = hang (text "Mismatched type name in type family instance.")
......
T5515.hs:9:3: error: T5515.hs:6:16: error:
The RHS of an associated type declaration mentions out-of-scope variable ‘a’ • Expecting one more argument to ‘ctx’
All such variables must be bound on the LHS Expected a type, but ‘ctx’ has kind ‘* -> Constraint’
• In the first argument of ‘Arg’, namely ‘ctx’
In the first argument of ‘ctx’, namely ‘(Arg ctx)’
In the class declaration for ‘Bome’
T5515.hs:15:3: error: T5515.hs:14:1: error:
The RHS of an associated type declaration mentions out-of-scope variable ‘a’ • Type variable ‘a’ is mentioned in the RHS,
All such variables must be bound on the LHS but not bound on the LHS of the family instance
• In the type instance declaration for ‘Arg’
In the instance declaration for ‘Some f’
T5515.hs:14:10: error:
• Could not deduce (C f a0)
from the context: C f a
bound by an instance declaration:
forall f a. C f a => Some f
at T5515.hs:14:10-24
The type variable ‘a0’ is ambiguous
• In the ambiguity check for an instance declaration
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the instance declaration for ‘Some f’
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module T16616a where
class C a where
type T a b
instance C (Maybe a) where
type forall b. T (Maybe a) b = Either a b
...@@ -166,4 +166,4 @@ test('T15994', [], run_command, ['$MAKE -s --no-print-directory T15994']) ...@@ -166,4 +166,4 @@ test('T15994', [], run_command, ['$MAKE -s --no-print-directory T15994'])
test('T15798a', normal, compile, ['']) test('T15798a', normal, compile, [''])
test('T15798b', normal, compile, ['']) test('T15798b', normal, compile, [''])
test('T15798c', normal, compile, ['']) test('T15798c', normal, compile, [''])
test('T16116a', normal, compile, [''])
{-# LANGUAGE TypeFamilies #-}
module T16116b where
class C a where
type F a
instance C [a] where
type F [a] = b
T16116b.hs:7:16: error: Not in scope: type variable ‘b’
...@@ -144,4 +144,5 @@ test('T15611b', normal, ghci_script, ['T15611b.script']) ...@@ -144,4 +144,5 @@ test('T15611b', normal, ghci_script, ['T15611b.script'])
test('T15828', normal, compile_fail, ['']) test('T15828', normal, compile_fail, [''])
test('T16002', normal, compile_fail, ['']) test('T16002', normal, compile_fail, [''])
test('T16114', normal, compile_fail, ['']) test('T16114', normal, compile_fail, [''])
test('T16116b', normal, compile_fail, [''])
test('ExplicitForAllRules2', normal, compile_fail, ['']) test('ExplicitForAllRules2', normal, compile_fail, [''])
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