diff options
author | sheaf <sam.derbyshire@gmail.com> | 2022-01-11 10:42:17 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-01-11 19:42:07 -0500 |
commit | 34d8bc24e33aa373acb6fdeef51427d968f28c0c (patch) | |
tree | 4eb89724f1b4e9e24ac3dc315497a5071ef463ef /compiler/GHC/Tc/Errors | |
parent | addf8e544841a3f7c818331e47fa89a2cbfb7b29 (diff) | |
download | haskell-34d8bc24e33aa373acb6fdeef51427d968f28c0c.tar.gz |
Fix parsing & printing of unboxed sums
The pretty-printing of partially applied unboxed sums was incorrect,
as we incorrectly dropped the first half of the arguments, even
for a partial application such as
(# | #) @IntRep @DoubleRep Int#
which lead to the nonsensical (# DoubleRep | Int# #).
This patch also allows users to write unboxed sum type constructors
such as
(# | #) :: TYPE r1 -> TYPE r2 -> TYPE (SumRep '[r1,r2]).
Fixes #20858 and #20859.
Diffstat (limited to 'compiler/GHC/Tc/Errors')
-rw-r--r-- | compiler/GHC/Tc/Errors/Ppr.hs | 15 | ||||
-rw-r--r-- | compiler/GHC/Tc/Errors/Types.hs | 10 |
2 files changed, 17 insertions, 8 deletions
diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs index fe3536157c..eb7a03febb 100644 --- a/compiler/GHC/Tc/Errors/Ppr.hs +++ b/compiler/GHC/Tc/Errors/Ppr.hs @@ -25,6 +25,7 @@ import GHC.Data.Bag import GHC.Tc.Errors.Types import GHC.Tc.Types.Rank (Rank(..)) import GHC.Tc.Utils.TcType (TcType, tcSplitForAllTyVars, mkClassPred) +import GHC.Types.Basic (UnboxedTupleOrSum(..), unboxedTupleOrSumExtension) import GHC.Types.Error import GHC.Types.FieldLabel (FieldLabelString, flIsOverloaded, flSelector) import GHC.Types.Id (isRecordSelector) @@ -201,10 +202,14 @@ instance Diagnostic TcRnMessage where TcRnConstraintInKind ty -> mkSimpleDecorated $ text "Illegal constraint in a kind:" <+> pprType ty - TcRnUnboxedTupleTypeFuncArg ty + TcRnUnboxedTupleOrSumTypeFuncArg tuple_or_sum ty -> mkSimpleDecorated $ - sep [ text "Illegal unboxed tuple type as function argument:" + sep [ text "Illegal unboxed" <+> what <+> text "type as function argument:" , pprType ty ] + where + what = case tuple_or_sum of + UnboxedTupleType -> text "tuple" + UnboxedSumType -> text "sum" TcRnLinearFuncInKind ty -> mkSimpleDecorated $ text "Illegal linear function in a kind:" <+> pprType ty @@ -630,7 +635,7 @@ instance Diagnostic TcRnMessage where -> ErrorWithoutFlag TcRnConstraintInKind{} -> ErrorWithoutFlag - TcRnUnboxedTupleTypeFuncArg{} + TcRnUnboxedTupleOrSumTypeFuncArg{} -> ErrorWithoutFlag TcRnLinearFuncInKind{} -> ErrorWithoutFlag @@ -852,8 +857,8 @@ instance Diagnostic TcRnMessage where -> noHints TcRnConstraintInKind{} -> noHints - TcRnUnboxedTupleTypeFuncArg{} - -> [suggestExtension LangExt.UnboxedTuples] + TcRnUnboxedTupleOrSumTypeFuncArg tuple_or_sum _ + -> [suggestExtension $ unboxedTupleOrSumExtension tuple_or_sum] TcRnLinearFuncInKind{} -> noHints TcRnForAllEscapeError{} diff --git a/compiler/GHC/Tc/Errors/Types.hs b/compiler/GHC/Tc/Errors/Types.hs index e84f30a7c0..f9de50f37a 100644 --- a/compiler/GHC/Tc/Errors/Types.hs +++ b/compiler/GHC/Tc/Errors/Types.hs @@ -635,8 +635,9 @@ data TcRnMessage where -} TcRnConstraintInKind :: !Type -> TcRnMessage - {-| TcRnUnboxedTupleTypeFuncArg is an error that occurs whenever an unboxed tuple type - is specified as a function argument. + {-| TcRnUnboxedTupleTypeFuncArg is an error that occurs whenever an unboxed tuple + or unboxed sum type is specified as a function argument, when the appropriate + extension (`-XUnboxedTuples` or `-XUnboxedSums`) isn't enabled. Examples(s): -- T15073.hs @@ -652,7 +653,10 @@ data TcRnMessage where deriving/should_fail/T15073a.hs typecheck/should_fail/T16059d -} - TcRnUnboxedTupleTypeFuncArg :: !Type -> TcRnMessage + TcRnUnboxedTupleOrSumTypeFuncArg + :: UnboxedTupleOrSum -- ^ whether this is an unboxed tuple or an unboxed sum + -> !Type + -> TcRnMessage {-| TcRnLinearFuncInKind is an error that occurs whenever a linear function is specified in a kind. |