[project @ 2002-05-29 13:09:24 by simonpj]
authorsimonpj <unknown>
Wed, 29 May 2002 13:09:24 +0000 (13:09 +0000)
committersimonpj <unknown>
Wed, 29 May 2002 13:09:24 +0000 (13:09 +0000)
Wibble to previous commit on negative literals in patterns (fixes crash in GHC/Real.lhs)

ghc/compiler/typecheck/TcPat.lhs

index e4decd0..548f710 100644 (file)
@@ -323,9 +323,15 @@ tcPat tc_bndr pat@(NPatIn over_lit mb_neg) pat_ty
              emptyBag, emptyBag, emptyLIE)
   where
     origin = PatOrigin pat
-    lit' = case over_lit of
-               HsIntegral i _   -> HsInteger i
-               HsFractional f _ -> HsRat f pat_ty
+
+       -- The literal in an NPatIn is always positive...
+       -- But in NPat, the literal is used to find identical patterns
+       --      so we must negate the literal when necessary!
+    lit' = case (over_lit, mb_neg) of
+            (HsIntegral i _, Nothing)   -> HsInteger i
+            (HsIntegral i _, Just _)    -> HsInteger (-i)
+            (HsFractional f _, Nothing) -> HsRat f pat_ty
+            (HsFractional f _, Just _)  -> HsRat (-f) pat_ty
 \end{code}
 
 %************************************************************************