From 7dd0a79cce7c4c048e7c145c9f378da3a96392d0 Mon Sep 17 00:00:00 2001 From: Alec Theriault Date: Sun, 23 Dec 2018 10:23:20 -0500 Subject: Properly synify and render promoted type variables (#985) * Synify and render properly promoted type variables Fixes #923. * Accept output --- haddock-api/src/Haddock/Backends/Xhtml/Decl.hs | 7 +- haddock-api/src/Haddock/Convert.hs | 3 +- html-test/ref/Bug548.html | 40 ++--- html-test/ref/Bug923.html | 200 +++++++++++++++++++++++++ html-test/ref/FunArgs.html | 2 +- html-test/ref/TypeFamilies.html | 36 ++--- html-test/src/Bug923.hs | 11 ++ 7 files changed, 256 insertions(+), 43 deletions(-) create mode 100644 html-test/ref/Bug923.html create mode 100644 html-test/src/Bug923.hs diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs b/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs index 4492739b..819a4747 100644 --- a/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs +++ b/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs @@ -34,7 +34,7 @@ import qualified Data.Map as Map import Data.Maybe import Text.XHtml hiding ( name, title, p, quote ) -import BasicTypes (PromotionFlag(..)) +import BasicTypes (PromotionFlag(..), isPromoted) import GHC hiding (LexicalFixity(..)) import GHC.Exts import Name @@ -1163,8 +1163,9 @@ ppr_mono_ty (HsTyVar _ _ (L _ name)) True _ _ ppr_mono_ty (HsBangTy _ b ty) u q _ = ppBang b +++ ppLParendType u q HideEmptyContexts ty -ppr_mono_ty (HsTyVar _ _ (L _ name)) _ q _ = - ppDocName q Prefix True name +ppr_mono_ty (HsTyVar _ prom (L _ name)) _ q _ + | isPromoted prom = promoQuote (ppDocName q Prefix True name) + | otherwise = ppDocName q Prefix True name ppr_mono_ty (HsStarTy _ isUni) u _ _ = toHtml (if u || isUni then "★" else "*") ppr_mono_ty (HsFunTy _ ty1 ty2) u q e = diff --git a/haddock-api/src/Haddock/Convert.hs b/haddock-api/src/Haddock/Convert.hs index 5ddc9eef..291af8de 100644 --- a/haddock-api/src/Haddock/Convert.hs +++ b/haddock-api/src/Haddock/Convert.hs @@ -500,9 +500,10 @@ synifyType _ (TyConApp tc tys) tys_rest -- Most TyCons: | otherwise - = mk_app_tys (HsTyVar noExt NotPromoted $ noLoc (getName tc)) + = mk_app_tys (HsTyVar noExt prom $ noLoc (getName tc)) vis_tys where + prom = if isPromotedDataCon tc then IsPromoted else NotPromoted mk_app_tys ty_app ty_args = foldl (\t1 t2 -> noLoc $ HsAppTy noExt t1 t2) (noLoc ty_app) diff --git a/html-test/ref/Bug548.html b/html-test/ref/Bug548.html index d7e120c9..1a906cc3 100644 --- a/html-test/ref/Bug548.html +++ b/html-test/ref/Bug548.html @@ -517,29 +517,29 @@ >Type) = D1 ( ('MetaData "WrappedArrow" "Control.Applicative" "base" "WrappedArrow" "Control.Applicative" "base" 'True) (C1 ( ('MetaCons "WrapArrow" "WrapArrow" 'PrefixI 'True) (S1 ( ('MetaSel ( ('Just "unwrapArrow") "unwrapArrow") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1WrappedArrow a b c) = D1 ( ('MetaData "WrappedArrow" "Control.Applicative" "base" "WrappedArrow" "Control.Applicative" "base" 'True) (C1 ( ('MetaCons "WrapArrow" "WrapArrow" 'PrefixI 'True) (S1 ( ('MetaSel ( ('Just "unwrapArrow") "unwrapArrow") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0Bug923
Safe HaskellSafe

Bug923

Synopsis
  • data T :: (* -> (*, *)) -> * where

Documentation

data T :: (* -> (*, *)) -> * where #

A promoted tuple type

Constructors

T :: a -> T ('(,) a)

Instances

Instances details
Eq a => Eq (T ('(,) a :: Type -> (Type, Type))) #

A promoted tuple type in an instance

Instance details

Defined in Bug923

Methods

(==) :: T ('(,) a) -> T ('(,) a) -> Bool #

(/=) :: T ('(,) a) -> T ('(,) a) -> Bool #

\ No newline at end of file diff --git a/html-test/ref/FunArgs.html b/html-test/ref/FunArgs.html index c9471477..59dfbb94 100644 --- a/html-test/ref/FunArgs.html +++ b/html-test/ref/FunArgs.html @@ -218,7 +218,7 @@ >:: forall (b :: ()). d ~ (b :: ()). d ~ '() 'XX >< 'XXX type 'XXX <> 'XX
type 'XXX <> 'XX = = 'X
Z -> Bat 'ZA
  • Z). {..} -> Bat 'ZB
  • Z -> Bat 'ZA
  • Z). {..} -> Bat 'ZB
  • type 'XXX <> 'XX
    type 'XXX <> 'XX = = 'X
    'XX >< 'XXX (*,*)) -> * where + T :: a -> T ('(,) a) + +-- | A promoted tuple type in an instance +instance Eq a => Eq (T ('(,) a)) where + T x == T y = x == y + -- cgit v1.2.3