diff options
author | sheaf <sam.derbyshire@gmail.com> | 2022-02-25 13:01:10 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-03-05 01:07:25 -0500 |
commit | 584cd5ae200866fbfb480fab9591f0acf94a8033 (patch) | |
tree | f0129eb9fdbe1513b11a300649ec5467be41eee7 /compiler/GHC/Tc | |
parent | 6f84ee332fd243e83004bdbc92a6970e96ab3189 (diff) | |
download | haskell-584cd5ae200866fbfb480fab9591f0acf94a8033.tar.gz |
Don't allow Float#/Double# literal patterns
This patch does the following two things:
1. Fix the check in Core Lint to properly throw an error when it
comes across Float#/Double# literal patterns. The check
was incorrect before, because it expected the type to be
Float/Double instead of Float#/Double#.
2. Add an error in the parser when the user writes a floating-point
literal pattern such as `case x of { 2.0## -> ... }`.
Fixes #21115
Diffstat (limited to 'compiler/GHC/Tc')
-rw-r--r-- | compiler/GHC/Tc/Utils/TcType.hs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/compiler/GHC/Tc/Utils/TcType.hs b/compiler/GHC/Tc/Utils/TcType.hs index b01f72b185..d538638279 100644 --- a/compiler/GHC/Tc/Utils/TcType.hs +++ b/compiler/GHC/Tc/Utils/TcType.hs @@ -78,7 +78,7 @@ module GHC.Tc.Utils.TcType ( pickyEqType, tcEqType, tcEqKind, tcEqTypeNoKindCheck, tcEqTypeVis, tcEqTyConApps, isSigmaTy, isRhoTy, isRhoExpTy, isOverloadedTy, - isFloatingTy, isDoubleTy, isFloatTy, isIntTy, isWordTy, isStringTy, + isFloatingPrimTy, isDoubleTy, isFloatTy, isIntTy, isWordTy, isStringTy, isIntegerTy, isNaturalTy, isBoolTy, isUnitTy, isCharTy, isTauTy, isTauTyCon, tcIsTyVarTy, tcIsForAllTy, @@ -1999,11 +1999,15 @@ isOverloadedTy (ForAllTy _ ty) = isOverloadedTy ty isOverloadedTy (FunTy { ft_af = InvisArg }) = True isOverloadedTy _ = False -isFloatTy, isDoubleTy, isIntegerTy, isNaturalTy, +isFloatTy, isDoubleTy, + isFloatPrimTy, isDoublePrimTy, + isIntegerTy, isNaturalTy, isIntTy, isWordTy, isBoolTy, isUnitTy, isCharTy, isAnyTy :: Type -> Bool isFloatTy = is_tc floatTyConKey isDoubleTy = is_tc doubleTyConKey +isFloatPrimTy = is_tc floatPrimTyConKey +isDoublePrimTy = is_tc doublePrimTyConKey isIntegerTy = is_tc integerTyConKey isNaturalTy = is_tc naturalTyConKey isIntTy = is_tc intTyConKey @@ -2013,9 +2017,15 @@ isUnitTy = is_tc unitTyConKey isCharTy = is_tc charTyConKey isAnyTy = is_tc anyTyConKey --- | Does a type represent a floating-point number? -isFloatingTy :: Type -> Bool -isFloatingTy ty = isFloatTy ty || isDoubleTy ty +-- | Is the type inhabited by machine floating-point numbers? +-- +-- Used to check that we don't use floating-point literal patterns +-- in Core. +-- +-- See #9238 and Note [Rules for floating-point comparisons] +-- in GHC.Core.Opt.ConstantFold. +isFloatingPrimTy :: Type -> Bool +isFloatingPrimTy ty = isFloatPrimTy ty || isDoublePrimTy ty -- | Is a type 'String'? isStringTy :: Type -> Bool |