diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-04-12 12:38:45 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-04-14 19:42:53 -0400 |
commit | cc1ba576d26b90c0c01aa43e7100c94ee3a287ad (patch) | |
tree | 3271e7d0fc6d614def8a06347c884d9bbec0caac /compiler/GHC | |
parent | 5f1722994dc29a86f5495ebafb15475a46b0532c (diff) | |
download | haskell-cc1ba576d26b90c0c01aa43e7100c94ee3a287ad.tar.gz |
Fix some negation issues when creating FractionalLit
There were two different issues:
1. integralFractionalLit needed to be passed an already negated value. (T19680)
2. negateFractionalLit did not actually negate the argument, only
flipped the negation flag. (T19680A)
Fixes #19680
Diffstat (limited to 'compiler/GHC')
-rw-r--r-- | compiler/GHC/HsToCore/Match.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Types/SourceText.hs | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/compiler/GHC/HsToCore/Match.hs b/compiler/GHC/HsToCore/Match.hs index d3b2776d93..6bd3860e42 100644 --- a/compiler/GHC/HsToCore/Match.hs +++ b/compiler/GHC/HsToCore/Match.hs @@ -1165,7 +1165,9 @@ patGroup _ (WildPat {}) = PgAny patGroup _ (BangPat {}) = PgBang patGroup _ (NPat _ (L _ (OverLit {ol_val=oval})) mb_neg _) = case (oval, isJust mb_neg) of - (HsIntegral i, is_neg) -> PgN (integralFractionalLit is_neg (il_value i)) + (HsIntegral i, is_neg) -> PgN (integralFractionalLit is_neg (if is_neg + then negate (il_value i) + else il_value i)) (HsFractional f, is_neg) | is_neg -> PgN $! negateFractionalLit f | otherwise -> PgN f diff --git a/compiler/GHC/Types/SourceText.hs b/compiler/GHC/Types/SourceText.hs index 59df5ddf9c..9faba4460b 100644 --- a/compiler/GHC/Types/SourceText.hs +++ b/compiler/GHC/Types/SourceText.hs @@ -222,10 +222,11 @@ mkTHFractionalLit r = FL { fl_text = SourceText (show (realToFrac r::Double)) negateFractionalLit :: FractionalLit -> FractionalLit negateFractionalLit (FL text neg i e eb) = case text of - SourceText ('-':src) -> FL (SourceText src) False i e eb - SourceText src -> FL (SourceText ('-':src)) True i e eb + SourceText ('-':src) -> FL (SourceText src) False (negate i) e eb + SourceText src -> FL (SourceText ('-':src)) True (negate i) e eb NoSourceText -> FL NoSourceText (not neg) (negate i) e eb +-- | The integer should already be negated if it's negative. integralFractionalLit :: Bool -> Integer -> FractionalLit integralFractionalLit neg i = FL { fl_text = SourceText (show i) , fl_neg = neg @@ -233,6 +234,7 @@ integralFractionalLit neg i = FL { fl_text = SourceText (show i) , fl_exp = 0 , fl_exp_base = Base10 } +-- | The arguments should already be negated if they are negative. mkSourceFractionalLit :: String -> Bool -> Integer -> Integer -> FractionalExponentBase -> FractionalLit |