git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #1524, render kinds as single line strings.
ad0dcb7Phil Freeman
src/Language/PureScript/Errors.hs+4−4
@@ -447,7 +447,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
447 ]
447 ]
448 renderSimpleErrorMessage (InfiniteKind ki) =
448 renderSimpleErrorMessage (InfiniteKind ki) =
449 paras [ line "An infinite kind was inferred for a type: "
449 paras [ line "An infinite kind was inferred for a type: "
450− , indent $ kindAsBox ki
450+ , indent $ line $ prettyPrintKind ki
451 ]
451 ]
452 renderSimpleErrorMessage (MultipleFixities name) =
452 renderSimpleErrorMessage (MultipleFixities name) =
453 line $ "Multiple fixity declarations for " ++ showIdent name
453 line $ "Multiple fixity declarations for " ++ showIdent name
@@ -542,9 +542,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
542 ]
542 ]
543 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
543 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
544 paras [ line "Cannot unify kind"
544 paras [ line "Cannot unify kind"
545− , indent $ kindAsBox k1
545+ , indent $ line $ prettyPrintKind k1
546 , line "with kind"
546 , line "with kind"
547− , indent $ kindAsBox k2
547+ , indent $ line $ prettyPrintKind k2
548 ]
548 ]
549 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
549 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
550 paras [ line "Cannot unify constrained type"
550 paras [ line "Cannot unify constrained type"
@@ -604,7 +604,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
604 , line "The error arises from the type"
604 , line "The error arises from the type"
605 , indent $ typeAsBox ty
605 , indent $ typeAsBox ty
606 , line "having the kind"
606 , line "having the kind"
607− , indent $ kindAsBox kind
607+ , indent $ line $ prettyPrintKind kind
608 , line "instead."
608 , line "instead."
609 ]
609 ]
610 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
610 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
src/Language/PureScript/Pretty/Kinds.hs+12−17
@@ -14,8 +14,7 @@
14-----------------------------------------------------------------------------
14-----------------------------------------------------------------------------
15
15
16module Language.PureScript.Pretty.Kinds (
16module Language.PureScript.Pretty.Kinds (
17− prettyPrintKind,
17+ prettyPrintKind
18− kindAsBox
19) where
18) where
20
19
21import Data.Maybe (fromMaybe)
20import Data.Maybe (fromMaybe)
@@ -24,15 +23,14 @@ import Control.Arrow (ArrowPlus(..))
24import Control.PatternArrows
23import Control.PatternArrows
25
24
26import Language.PureScript.Kinds
25import Language.PureScript.Kinds
26+import Language.PureScript.Pretty.Common
27
27
28−import Text.PrettyPrint.Boxes (Box(), text, render, (<>))
29−
30−typeLiterals :: Pattern () Kind Box
28+typeLiterals :: Pattern () Kind String
31typeLiterals = mkPattern match
29typeLiterals = mkPattern match
32 where
30 where
33− match Star = Just $ text "*"
31+ match Star = Just "*"
34− match Bang = Just $ text "!"
32+ match Bang = Just "!"
35− match (KUnknown u) = Just $ text $ 'u' : show u
33+ match (KUnknown u) = Just $ 'u' : show u
36 match _ = Nothing
34 match _ = Nothing
37
35
38matchRow :: Pattern () Kind ((), Kind)
36matchRow :: Pattern () Kind ((), Kind)
@@ -49,15 +47,12 @@ funKind = mkPattern match
49
47
50-- | Generate a pretty-printed string representing a Kind
48-- | Generate a pretty-printed string representing a Kind
51prettyPrintKind :: Kind -> String
49prettyPrintKind :: Kind -> String
52−prettyPrintKind = render . kindAsBox
53−
54−kindAsBox :: Kind -> Box
55−kindAsBox = fromMaybe (error "Incomplete pattern") . pattern matchKind ()
50+prettyPrintKind = fromMaybe (error "Incomplete pattern") . pattern matchKind ()
56 where
51 where
57− matchKind :: Pattern () Kind Box
52+ matchKind :: Pattern () Kind String
58− matchKind = buildPrettyPrinter operators (typeLiterals <+> fmap ((text "(" <>) . (<> text ")")) matchKind)
53+ matchKind = buildPrettyPrinter operators (typeLiterals <+> fmap parens matchKind)
59
54
60− operators :: OperatorTable () Kind Box
55+ operators :: OperatorTable () Kind String
61 operators =
56 operators =
62− OperatorTable [ [ Wrap matchRow $ \_ k -> text "# " <> k]
57+ OperatorTable [ [ Wrap matchRow $ \_ k -> "# " ++ k]
63− , [ AssocR funKind $ \arg ret -> arg <> text " -> " <> ret ] ]
58+ , [ AssocR funKind $ \arg ret -> arg ++ " -> " ++ ret ] ]
src/Language/PureScript/Pretty/Types.hs+1−1
@@ -124,7 +124,7 @@ matchType = buildPrettyPrinter operators matchTypeAtom
124 , [ AssocR appliedFunction $ \arg ret -> (arg <> text " ") `before` (text "-> " <> ret)
124 , [ AssocR appliedFunction $ \arg ret -> (arg <> text " ") `before` (text "-> " <> ret)
125 ]
125 ]
126 , [ Wrap forall_ $ \idents ty -> text ("forall " ++ unwords idents ++ ". ") <> ty ]
126 , [ Wrap forall_ $ \idents ty -> text ("forall " ++ unwords idents ++ ". ") <> ty ]
127− , [ Wrap kinded $ \k ty -> ty `before` (text " :: " <> kindAsBox k) ]
127+ , [ Wrap kinded $ \k ty -> ty `before` (text (" :: " ++ prettyPrintKind k)) ]
128 ]
128 ]
129
129
130forall_ :: Pattern () Type ([String], Type)
130forall_ :: Pattern () Type ([String], Type)