From d113ae78f633ea5b12a24e4fcb7693d961869d3e Mon Sep 17 00:00:00 2001 From: simonmar Date: Wed, 13 Feb 2002 15:08:00 +0000 Subject: [PATCH] [project @ 2002-02-13 15:07:59 by simonmar] Don't translate out negative (boxed) literals too early. --- ghc/compiler/parser/ParseUtil.lhs | 8 ++++++++ ghc/compiler/parser/RdrHsSyn.lhs | 12 +----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ghc/compiler/parser/ParseUtil.lhs b/ghc/compiler/parser/ParseUtil.lhs index ca546b8..04fd6df 100644 --- a/ghc/compiler/parser/ParseUtil.lhs +++ b/ghc/compiler/parser/ParseUtil.lhs @@ -198,6 +198,14 @@ checkPat e [] = case e of in returnP (SigPatIn e t') + -- translate out NegApps of literals in patterns. + -- NB. negative primitive literals are already handled by + -- RdrHsSyn.mkHsNegApp + NegApp (HsOverLit (HsIntegral i n)) _ + -> returnP (NPatIn (HsIntegral (-i) n)) + NegApp (HsOverLit (HsFractional f n)) _ + -> returnP (NPatIn (HsFractional (-f) n)) + OpApp (HsVar n) (HsVar plus) _ (HsOverLit lit@(HsIntegral _ _)) | plus == plus_RDR -> returnP (mkNPlusKPat n lit) diff --git a/ghc/compiler/parser/RdrHsSyn.lhs b/ghc/compiler/parser/RdrHsSyn.lhs index c482844..6626fce 100644 --- a/ghc/compiler/parser/RdrHsSyn.lhs +++ b/ghc/compiler/parser/RdrHsSyn.lhs @@ -237,21 +237,11 @@ mkHsNegApp :: RdrNameHsExpr -> RdrNameHsExpr -- If the type checker sees (negate 3#) it will barf, because negate -- can't take an unboxed arg. But that is exactly what it will see when -- we write "-3#". So we have to do the negation right now! --- --- We also do the same service for boxed literals, because this function --- is also used for patterns (which, remember, are parsed as expressions) --- and pattern don't have negation in them. --- --- Finally, it's important to represent minBound as minBound, and not --- as (negate (-minBound)), becuase the latter is out of range. mkHsNegApp (HsLit (HsIntPrim i)) = HsLit (HsIntPrim (-i)) mkHsNegApp (HsLit (HsFloatPrim i)) = HsLit (HsFloatPrim (-i)) mkHsNegApp (HsLit (HsDoublePrim i)) = HsLit (HsDoublePrim (-i)) - -mkHsNegApp (HsOverLit (HsIntegral i n)) = HsOverLit (HsIntegral (-i) n) -mkHsNegApp (HsOverLit (HsFractional f n)) = HsOverLit (HsFractional (-f) n) -mkHsNegApp expr = NegApp expr negateName +mkHsNegApp expr = NegApp expr negateName \end{code} A useful function for building @OpApps@. The operator is always a -- 1.7.10.4