Commit f1baea44 authored by simonmar's avatar simonmar
Browse files

[project @ 2001-03-23 17:34:44 by simonmar]

Fix the long-standing overlapping patterns bug with string-literal
patterns.
parent a4b7cd97
...@@ -13,17 +13,16 @@ module Check ( check , ExhaustivePat ) where ...@@ -13,17 +13,16 @@ module Check ( check , ExhaustivePat ) where
import HsSyn import HsSyn
import TcHsSyn ( TypecheckedPat ) import TcHsSyn ( TypecheckedPat )
import DsHsSyn ( outPatType ) import DsHsSyn ( outPatType )
import DsUtils ( EquationInfo(..), MatchResult(..), EqnSet, CanItFail(..), import DsUtils ( EquationInfo(..), MatchResult(..), EqnSet,
tidyLitPat CanItFail(..), tidyLitPat, tidyNPat,
) )
import Id ( idType ) import Id ( idType )
import DataCon ( DataCon, dataConTyCon, dataConArgTys, import DataCon ( DataCon, dataConTyCon, dataConArgTys,
dataConSourceArity, dataConFieldLabels ) dataConSourceArity, dataConFieldLabels )
import Name ( Name, mkLocalName, getOccName, isDataSymOcc, getName, mkVarOcc ) import Name ( Name, mkLocalName, getOccName, isDataSymOcc, getName, mkVarOcc )
import Type ( splitAlgTyConApp, mkTyVarTys, splitTyConApp_maybe ) import Type ( splitAlgTyConApp, mkTyVarTys, splitTyConApp_maybe )
import TysWiredIn ( nilDataCon, consDataCon, import TysPrim ( charPrimTy )
mkListTy, mkTupleTy, tupleCon import TysWiredIn
)
import PrelNames ( unboundKey ) import PrelNames ( unboundKey )
import TyCon ( tyConDataCons, tupleTyConBoxity, isTupleTyCon ) import TyCon ( tyConDataCons, tupleTyConBoxity, isTupleTyCon )
import BasicTypes ( Boxity(..) ) import BasicTypes ( Boxity(..) )
...@@ -617,7 +616,17 @@ simplify_pat (RecPat dc ty ex_tvs dicts idps) ...@@ -617,7 +616,17 @@ simplify_pat (RecPat dc ty ex_tvs dicts idps)
| otherwise = x : insertNm nm p xs | otherwise = x : insertNm nm p xs
simplify_pat pat@(LitPat lit lit_ty) = tidyLitPat lit pat simplify_pat pat@(LitPat lit lit_ty) = tidyLitPat lit pat
simplify_pat pat@(NPat lit lit_ty hsexpr) = tidyLitPat lit pat
-- unpack string patterns fully, so we can see when they overlap with
-- each other, or even explicit lists of Chars.
simplify_pat pat@(NPat (HsString s) _ _) =
foldr (\c pat -> ConPat consDataCon stringTy [] [] [mk_char_lit c,pat])
(ConPat nilDataCon stringTy [] [] []) (_UNPK_INT_ s)
where
mk_char_lit c = ConPat charDataCon charTy [] []
[LitPat (HsCharPrim c) charPrimTy]
simplify_pat pat@(NPat lit lit_ty hsexpr) = tidyNPat lit lit_ty pat
simplify_pat (NPlusKPat id hslit ty hsexpr1 hsexpr2) = simplify_pat (NPlusKPat id hslit ty hsexpr1 hsexpr2) =
WildPat ty WildPat ty
......
Supports Markdown
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