summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorHE, Tao <sighingnow@gmail.com>2018-05-03 17:16:09 -0400
committerBen Gamari <ben@smart-cactus.org>2018-05-05 13:09:18 -0400
commit361d23a8ebb44f5df5167306d7b98d8bd1724e06 (patch)
tree7e598b327504115635739af5a30188bce41b7d04 /compiler
parent426ae98852be498fa87d10e4c88ba8d726d6b320 (diff)
downloadhaskell-361d23a8ebb44f5df5167306d7b98d8bd1724e06.tar.gz
Normalize the element type of ListPat, fix #14547
The element type of `List` maybe a type family instacen, rather than a trivial type. For example in Trac #14547, ``` {-# LANGUAGE TypeFamilies, OverloadedLists #-} class Foo f where type It f foo :: [It f] -> f data List a = Empty | a :! List a deriving Show instance Foo (List a) where type It (List a) = a foo [] = Empty foo (x : xs) = x :! foo xs ``` Here the element type of `[]` is `It (List a)`, we should also normalize it as `a`. Test Plan: make test TEST="T14547" Reviewers: bgamari Reviewed By: bgamari Subscribers: thomie, carter GHC Trac Issues: #14547 Differential Revision: https://phabricator.haskell.org/D4624
Diffstat (limited to 'compiler')
-rw-r--r--compiler/deSugar/Check.hs5
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/deSugar/Check.hs b/compiler/deSugar/Check.hs
index 545aacef51..7a5f889423 100644
--- a/compiler/deSugar/Check.hs
+++ b/compiler/deSugar/Check.hs
@@ -790,10 +790,13 @@ translatePat fam_insts pat = case pat of
-- overloaded list
ListPat (ListPatTc elem_ty (Just (pat_ty, _to_list))) lpats
| Just e_ty <- splitListTyConApp_maybe pat_ty
+ , (_, norm_e_ty) <- normaliseType fam_insts Nominal e_ty
+ -- e_ty can be a type family instance, like
+ -- `It (List a)`, but we prefer `a`, see Trac #14547
, (_, norm_elem_ty) <- normaliseType fam_insts Nominal elem_ty
-- elem_ty is frequently something like
-- `Item [Int]`, but we prefer `Int`
- , norm_elem_ty `eqType` e_ty ->
+ , norm_elem_ty `eqType` norm_e_ty ->
-- We have to ensure that the element types are exactly the same.
-- Otherwise, one may give an instance IsList [Int] (more specific than
-- the default IsList [a]) with a different implementation for `toList'