From 9a5b04a98c6de51970d8b0eea3989cf610f0cd6d Mon Sep 17 00:00:00 2001 From: Brian Huffman Date: Tue, 28 Jul 2020 13:34:24 -0700 Subject: [PATCH 1/2] Place parens appropriately when pretty printing types. Fixes #835. --- src/Cryptol/TypeCheck/Type.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Cryptol/TypeCheck/Type.hs b/src/Cryptol/TypeCheck/Type.hs index 32abaa77d..a7e070afe 100644 --- a/src/Cryptol/TypeCheck/Type.hs +++ b/src/Cryptol/TypeCheck/Type.hs @@ -834,7 +834,16 @@ instance PP (WithNames Newtype) where - +-- | The precedence levels used by this pretty-printing instance +-- correspond with parser non-terminals as follows: +-- +-- * 0-1: @type@ +-- +-- * 2: @infix_type@ +-- +-- * 3: @app_type@ +-- +-- * 4: @atype@ instance PP (WithNames Type) where ppPrec prec ty0@(WithNames ty nmMap) = case ty of @@ -867,7 +876,7 @@ instance PP (WithNames Type) where (TCTuple _, fs) -> parens $ fsep $ punctuate comma $ map (go 0) fs - (_, _) -> pp tc <+> fsep (map (go 5) ts) + (_, _) -> optParens (prec > 3) $ pp tc <+> fsep (map (go 4) ts) TCon (PC pc) ts -> case (pc,ts) of From e48e9f8302351392d597c4956b43175c465f79e5 Mon Sep 17 00:00:00 2001 From: Brian Huffman Date: Tue, 28 Jul 2020 13:50:16 -0700 Subject: [PATCH 2/2] Add regression test for issue #835. --- tests/issues/issue835.icry | 2 ++ tests/issues/issue835.icry.stdout | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/issues/issue835.icry create mode 100644 tests/issues/issue835.icry.stdout diff --git a/tests/issues/issue835.icry b/tests/issues/issue835.icry new file mode 100644 index 000000000..1e6d493c9 --- /dev/null +++ b/tests/issues/issue835.icry @@ -0,0 +1,2 @@ +:m Float +:t (zero : Float 5 11) <$ zero diff --git a/tests/issues/issue835.icry.stdout b/tests/issues/issue835.icry.stdout new file mode 100644 index 000000000..da04b3e2e --- /dev/null +++ b/tests/issues/issue835.icry.stdout @@ -0,0 +1,10 @@ +Loading module Cryptol +Loading module Cryptol +Loading module Float + +[error] at :1:1--1:28: + Unsolved constraints: + • SignedCmp (Float 5 11) + arising from + use of expression (<$) + at :1:1--1:28