Commit 1b9d32b8 authored by Ryan Scott's avatar Ryan Scott Committed by Marge Bot

Rip out 9-year-old pattern variable hack (#17007)

GHC had an ad hoc validity check in place to rule out pattern
variables bound by type synonyms, such as in the following example:

```hs
type ItemColID a b = Int  -- Discards a,b

get :: ItemColID a b -> ItemColID a b
get (x :: ItemColID a b) = x :: ItemColID a b
```

This hack is wholly unnecessary nowadays, since OutsideIn(X) is more
than capable of instantiating `a` and `b` to `Any`. In light of this,
let's rip out this validity check.

Fixes #17007.
parent 95521140
......@@ -2787,17 +2787,6 @@ tcPatSig in_pat_bind sig res_ty
-- than in the renamer
{ when in_pat_bind (addErr (patBindSigErr sig_tvs))
-- Check that all newly-in-scope tyvars are in fact
-- constrained by the pattern. This catches tiresome
-- cases like
-- type T a = Int
-- f :: Int -> Int
-- f (x :: T a) = ...
-- Here 'a' doesn't get a binding. Sigh
; let bad_tvs = filterOut (`elemVarSet` exactTyCoVarsOfType sig_ty)
(tyCoVarsOfTypeList sig_ty)
; checkTc (null bad_tvs) (badPatTyVarTvs sig_ty bad_tvs)
-- Now do a subsumption check of the pattern signature against res_ty
; wrap <- addErrCtxtM (mk_msg sig_ty) $
tcSubTypeET PatSigOrigin PatSigCtxt res_ty sig_ty
......@@ -3000,23 +2989,6 @@ promotionErr name err
PatSynPE -> text "pattern synonyms cannot be promoted"
_ -> text "it is defined and used in the same recursive group"
{-
************************************************************************
* *
Scoped type variables
* *
************************************************************************
-}
badPatTyVarTvs :: TcType -> [TyVar] -> SDoc
badPatTyVarTvs sig_ty bad_tvs
= vcat [ fsep [text "The type variable" <> plural bad_tvs,
quotes (pprWithCommas ppr bad_tvs),
text "should be bound by the pattern signature" <+> quotes (ppr sig_ty),
text "but are actually discarded by a type synonym" ]
, text "To fix this, expand the type synonym"
, text "[Note: I hope to lift this restriction in due course]" ]
{-
************************************************************************
* *
......
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module T17007 where
type ItemColID a b = Int -- Discards a,b
get :: ItemColID a b -> ItemColID a b
get (x :: ItemColID a b) = x :: ItemColID a b
type family ItemColID' a b where ItemColID' a b = Int -- Discards a,b
get' :: ItemColID' a b -> ItemColID' a b
get' (x :: ItemColID' a b) = x :: ItemColID' a b
......@@ -685,3 +685,4 @@ test('UnliftedNewtypesLPFamily', normal, compile, [''])
test('UnliftedNewtypesDifficultUnification', normal, compile, [''])
test('T16832', normal, ghci_script, ['T16832.script'])
test('T16946', normal, compile, [''])
test('T17007', normal, compile, [''])
T3406.hs:11:6:
The type variables ‘a, b’
should be bound by the pattern signature ‘ItemColID a b
but are actually discarded by a type synonym
To fix this, expand the type synonym
[Note: I hope to lift this restriction in due course]
In the pattern: x :: ItemColID a b
In an equation for ‘get’:
get (x :: ItemColID a b) = x :: ItemColID a b
T3406.hs:11:28: error:
• Couldn't match type ‘Int’ with ‘a -> ItemColID a b’
Expected type: a -> ItemColID a b
Actual type: ItemColID a1 b1
• In the expression: x :: ItemColID a b
In an equation for ‘get’:
get (x :: ItemColID a b) = x :: ItemColID a b
• Relevant bindings include
get :: ItemColID a b -> a -> ItemColID a b (bound at T3406.hs:11:1)
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