summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorJohn Leo <leo@halfaya.org>2016-12-13 14:57:15 -0500
committerBen Gamari <ben@smart-cactus.org>2016-12-13 15:38:33 -0500
commit7031704332db55de1fc3c46a8f450bad933997e0 (patch)
treeda3d099939e1951c5286a7804dc42a8685b28d19 /compiler
parentaa123f445338c2980fcee87a09c01d14a83bf409 (diff)
downloadhaskell-7031704332db55de1fc3c46a8f450bad933997e0.tar.gz
print * in unicode correctly (fixes #12550)
Test Plan: validate Reviewers: simonpj, austin, bgamari, goldfire Reviewed By: bgamari, goldfire Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2829
Diffstat (limited to 'compiler')
-rw-r--r--compiler/basicTypes/BasicTypes.hs2
-rw-r--r--compiler/iface/IfaceType.hs21
-rw-r--r--compiler/types/TyCoRep.hs4
-rw-r--r--compiler/utils/Outputable.hs5
4 files changed, 18 insertions, 14 deletions
diff --git a/compiler/basicTypes/BasicTypes.hs b/compiler/basicTypes/BasicTypes.hs
index 20533a8516..7e1f2c7b70 100644
--- a/compiler/basicTypes/BasicTypes.hs
+++ b/compiler/basicTypes/BasicTypes.hs
@@ -692,7 +692,7 @@ pprSafeOverlap False = empty
************************************************************************
-}
-data TyPrec -- See Note [Prededence in types]
+data TyPrec -- See Note [Precedence in types] in TyCoRep.hs
= TopPrec -- No parens
| FunPrec -- Function args; no parens for tycon apps
| TyOpPrec -- Infix operator
diff --git a/compiler/iface/IfaceType.hs b/compiler/iface/IfaceType.hs
index dbca426cbe..b667522007 100644
--- a/compiler/iface/IfaceType.hs
+++ b/compiler/iface/IfaceType.hs
@@ -188,7 +188,7 @@ data IfaceTyConSort = IfaceNormalTyCon -- ^ a regular tycon
{- Note [TcTyVars in IfaceType]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Nowadays (since Nov 16) we pretty-print a Type by converting to an
+Nowadays (since Nov 16, 2016) we pretty-print a Type by converting to an
IfaceType and pretty printing that. This eliminates a lot of
pretty-print duplication, and it matches what we do with
pretty-printing TyThings.
@@ -966,7 +966,7 @@ pprTyTcApp' ctxt_prec tc tys dflags style
| tc `ifaceTyConHasKey` tYPETyConKey
, ITC_Vis (IfaceTyConApp rep ITC_Nil) ITC_Nil <- tys
, rep `ifaceTyConHasKey` ptrRepLiftedDataConKey
- = unicodeSyntax (char '★') (char '*')
+ = kindStar
| tc `ifaceTyConHasKey` tYPETyConKey
, ITC_Vis (IfaceTyConApp rep ITC_Nil) ITC_Nil <- tys
@@ -1050,22 +1050,23 @@ ppr_iface_tc_app pp _ tc [ty]
| tc `ifaceTyConHasKey` parrTyConKey = pprPromotionQuote tc <> paBrackets (pp TopPrec ty)
ppr_iface_tc_app pp ctxt_prec tc tys
- | not (isSymOcc (nameOccName tc_name))
+ | tc `ifaceTyConHasKey` starKindTyConKey
+ || tc `ifaceTyConHasKey` liftedTypeKindTyConKey
+ || tc `ifaceTyConHasKey` unicodeStarKindTyConKey
+ = kindStar -- Handle unicode; do not wrap * in parens
+
+ | tc `ifaceTyConHasKey` unliftedTypeKindTyConKey
+ = ppr tc -- Do not wrap # in parens
+
+ | not (isSymOcc (nameOccName (ifaceTyConName tc)))
= pprIfacePrefixApp ctxt_prec (ppr tc) (map (pp TyConPrec) tys)
| [ty1,ty2] <- tys -- Infix, two arguments;
-- we know nothing of precedence though
= pprIfaceInfixApp pp ctxt_prec (ppr tc) ty1 ty2
- | tc `ifaceTyConHasKey` starKindTyConKey
- || tc `ifaceTyConHasKey` unliftedTypeKindTyConKey
- || tc `ifaceTyConHasKey` unicodeStarKindTyConKey
- = ppr tc -- Do not wrap *, # in parens
-
| otherwise
= pprIfacePrefixApp ctxt_prec (parens (ppr tc)) (map (pp TyConPrec) tys)
- where
- tc_name = ifaceTyConName tc
pprSum :: Arity -> IsPromoted -> IfaceTcArgs -> SDoc
pprSum _arity is_promoted args
diff --git a/compiler/types/TyCoRep.hs b/compiler/types/TyCoRep.hs
index 6680ca816b..c007321988 100644
--- a/compiler/types/TyCoRep.hs
+++ b/compiler/types/TyCoRep.hs
@@ -2368,7 +2368,7 @@ works just by setting the initial context precedence very high.
Note [Precedence in types]
~~~~~~~~~~~~~~~~~~~~~~~~~~
We don't keep the fixity of type operators in the operator. So the pretty printer
-operates the following precedene structre:
+follows the following precedence order:
Type constructor application binds more tightly than
Operator applications which bind more tightly than
Function arrow
@@ -2378,7 +2378,7 @@ meaning (a :+: (T b)) -> c
Maybe operator applications should bind a bit less tightly?
-Anyway, that's the current story, and it is used consistently for Type and HsType
+Anyway, that's the current story; it is used consistently for Type and HsType.
-}
------------------
diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs
index 32d1b5dac9..371856f5ea 100644
--- a/compiler/utils/Outputable.hs
+++ b/compiler/utils/Outputable.hs
@@ -29,7 +29,7 @@ module Outputable (
semi, comma, colon, dcolon, space, equals, dot, vbar,
arrow, larrow, darrow, arrowt, larrowt, arrowtt, larrowtt,
lparen, rparen, lbrack, rbrack, lbrace, rbrace, underscore,
- blankLine, forAllLit,
+ blankLine, forAllLit, kindStar,
(<>), (<+>), hcat, hsep,
($$), ($+$), vcat,
sep, cat,
@@ -590,6 +590,9 @@ rbrace = docToSDoc $ Pretty.rbrace
forAllLit :: SDoc
forAllLit = unicodeSyntax (char '∀') (text "forall")
+kindStar :: SDoc
+kindStar = unicodeSyntax (char '★') (char '*')
+
unicodeSyntax :: SDoc -> SDoc -> SDoc
unicodeSyntax unicode plain = sdocWithDynFlags $ \dflags ->
if useUnicode dflags && useUnicodeSyntax dflags