From 99619d681c571849d0fa072705db6f3490383107 Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Mon, 8 Jul 2019 21:25:05 +0200 Subject: [PATCH] Fix rendering of implicit bidirectional pattern synonyms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously we forgot to enable the extension, and apparently we were just defining a function called ‘pattern’. --- .../value/pattern-synonyms/bidirectional-out.hs | 4 ++++ .../value/pattern-synonyms/bidirectional.hs | 2 ++ .../explicitely-bidirectional-out.hs | 6 ++++++ .../pattern-synonyms/explicitely-bidirectional.hs | 4 ++++ .../value/pattern-synonyms/unidirectional-out.hs | 2 ++ .../value/pattern-synonyms/unidirectional.hs | 2 ++ src/Ormolu/Printer/Meat/Declaration/Value.hs | 12 ++++++++---- 7 files changed, 28 insertions(+), 4 deletions(-) diff --git a/data/examples/declaration/value/pattern-synonyms/bidirectional-out.hs b/data/examples/declaration/value/pattern-synonyms/bidirectional-out.hs index a4d001a..4577887 100644 --- a/data/examples/declaration/value/pattern-synonyms/bidirectional-out.hs +++ b/data/examples/declaration/value/pattern-synonyms/bidirectional-out.hs @@ -1,6 +1,10 @@ +{-# LANGUAGE PatternSynonyms #-} + pattern Arrow t1 t2 = App "->" [t1, t2] + pattern Int = App "Int" [] + pattern Maybe t = App "Maybe" diff --git a/data/examples/declaration/value/pattern-synonyms/bidirectional.hs b/data/examples/declaration/value/pattern-synonyms/bidirectional.hs index 8c63329..59c35ad 100644 --- a/data/examples/declaration/value/pattern-synonyms/bidirectional.hs +++ b/data/examples/declaration/value/pattern-synonyms/bidirectional.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE PatternSynonyms #-} + pattern Arrow t1 t2 = App "->" [t1, t2] pattern Int = App "Int" [] diff --git a/data/examples/declaration/value/pattern-synonyms/explicitely-bidirectional-out.hs b/data/examples/declaration/value/pattern-synonyms/explicitely-bidirectional-out.hs index fc6e680..a685849 100644 --- a/data/examples/declaration/value/pattern-synonyms/explicitely-bidirectional-out.hs +++ b/data/examples/declaration/value/pattern-synonyms/explicitely-bidirectional-out.hs @@ -9,3 +9,9 @@ pattern HeadC' x <- x : xs where HeadC' x = [x] + +pattern Simple <- + "Simple" + where + Simple = + "Complicated" diff --git a/data/examples/declaration/value/pattern-synonyms/explicitely-bidirectional.hs b/data/examples/declaration/value/pattern-synonyms/explicitely-bidirectional.hs index 90fd309..b2ae253 100644 --- a/data/examples/declaration/value/pattern-synonyms/explicitely-bidirectional.hs +++ b/data/examples/declaration/value/pattern-synonyms/explicitely-bidirectional.hs @@ -7,3 +7,7 @@ pattern HeadC' x <- x:xs where HeadC' x = [x] + +pattern Simple <- "Simple" + where + Simple = "Complicated" diff --git a/data/examples/declaration/value/pattern-synonyms/unidirectional-out.hs b/data/examples/declaration/value/pattern-synonyms/unidirectional-out.hs index 59d7a53..5cf5b8e 100644 --- a/data/examples/declaration/value/pattern-synonyms/unidirectional-out.hs +++ b/data/examples/declaration/value/pattern-synonyms/unidirectional-out.hs @@ -4,3 +4,5 @@ pattern Head x <- x : xs pattern Head' x <- x : xs + +pattern Simple <- "Simple" diff --git a/data/examples/declaration/value/pattern-synonyms/unidirectional.hs b/data/examples/declaration/value/pattern-synonyms/unidirectional.hs index 8155a85..19830b2 100644 --- a/data/examples/declaration/value/pattern-synonyms/unidirectional.hs +++ b/data/examples/declaration/value/pattern-synonyms/unidirectional.hs @@ -4,3 +4,5 @@ pattern Head x <- x:xs pattern Head' x <- x:xs + +pattern Simple <- "Simple" diff --git a/src/Ormolu/Printer/Meat/Declaration/Value.hs b/src/Ormolu/Printer/Meat/Declaration/Value.hs index f3fbbd5..c239005 100644 --- a/src/Ormolu/Printer/Meat/Declaration/Value.hs +++ b/src/Ormolu/Printer/Meat/Declaration/Value.hs @@ -575,24 +575,28 @@ p_hsExpr = \case p_patSynBind :: PatSynBind GhcPs GhcPs -> R () p_patSynBind PSB {..} = do txt "pattern " + let nonEmptySynDetails = \case + PrefixCon (_:_) -> True + RecCon (_:_) -> True + _ -> False case psb_dir of Unidirectional -> do p_rdrName psb_id - space + when (nonEmptySynDetails psb_args) space p_patSynDetails psb_args txt " <-" breakpoint inci (located psb_def p_pat) ImplicitBidirectional -> do p_rdrName psb_id - space + when (nonEmptySynDetails psb_args) space p_patSynDetails psb_args txt " =" breakpoint - located psb_def p_pat + inci (located psb_def p_pat) ExplicitBidirectional mgroup -> do p_rdrName psb_id - space + when (nonEmptySynDetails psb_args) space p_patSynDetails psb_args txt " <-" breakpoint