From 584cd5ae200866fbfb480fab9591f0acf94a8033 Mon Sep 17 00:00:00 2001 From: sheaf Date: Fri, 25 Feb 2022 13:01:10 +0100 Subject: 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 --- compiler/GHC/Tc/Utils/TcType.hs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'compiler/GHC/Tc') 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 -- cgit v1.2.1