on master help sign in
Handle operators as record fields
commited27fb4a9a1258bbee867d2a02278f0b56821d40 authorUtku Demir <me@utdemir.com> dateMon 16 Sep 2019, 14:55 (7 years ago) parenta83796b
5 files changed+24−7
data/examples/declaration/value/function/record-constructors-out.hs+2 data/examples/declaration/value/function/record-constructors.hs+1−1 data/examples/declaration/value/function/record-updaters-out.hs+2 data/examples/declaration/value/function/record-updaters.hs+1 src/Ormolu/Printer/Meat/Declaration/Value.hs+18−6
data/examples/declaration/value/function/record-constructors-out.hs+2
@@ -7,6 +7,8 @@ bar = Bar
77
88baz = Baz {}
99
10+sym = Foo {(+) = 3}
11+
1012aLongVariableName =
1113 ALongRecordName
1214 { short = baz,
data/examples/declaration/value/function/record-constructors.hs+1−1
@@ -4,7 +4,7 @@ bar = Bar {
44 def = Foo {a = 10}
55}
66baz = Baz{ }
7−
7+sym = Foo { (+) = 3 }
88aLongVariableName =
99 ALongRecordName
1010 { short = baz,
data/examples/declaration/value/function/record-updaters-out.hs+2
@@ -7,3 +7,5 @@ bar x =
77 }
88
99baz x = x {}
10+
11+sym x = x {(+) = 4}
data/examples/declaration/value/function/record-updaters.hs+1
@@ -4,3 +4,4 @@ bar x = x {
44 def = Foo {a = 10}
55}
66baz x = x{ }
7+sym x = x { (+) = 4 }
src/Ormolu/Printer/Meat/Declaration/Value.hs+18−6
@@ -29,7 +29,6 @@ import Ormolu.Printer.Meat.Declaration.Signature
2929import Ormolu.Printer.Meat.Type
3030import Ormolu.Printer.Operators
3131import Ormolu.Utils
32−import Outputable (Outputable (..))
3332import RdrName (rdrNameOcc)
3433import SrcLoc (combineSrcSpans, isOneLineSpan)
3534import qualified Data.List.NonEmpty as NE
@@ -469,11 +468,10 @@ p_hsLocalBinds = \case
469468 XHsLocalBindsLR _ -> notImplemented "XHsLocalBindsLR"
470469
471470p_hsRecField
472− :: (Data id, Outputable id)
473− => HsRecField' id (LHsExpr GhcPs)
471+ :: HsRecField' RdrName (LHsExpr GhcPs)
474472 -> R ()
475473p_hsRecField = \HsRecField {..} -> do
476− located hsRecFieldLbl atom
474+ p_rdrName hsRecFieldLbl
477475 unless hsRecPun $ do
478476 space
479477 txt "="
@@ -630,7 +628,12 @@ p_hsExpr = \case
630628 located rcon_con_name atom
631629 breakpoint
632630 let HsRecFields {..} = rcon_flds
633− fields = located' p_hsRecField <$> rec_flds
631+ updName f = f {
632+ hsRecFieldLbl = case unLoc $ hsRecFieldLbl f of
633+ FieldOcc _ n -> n
634+ XFieldOcc _ -> notImplemented "XFieldOcc"
635+ }
636+ fields = located' (p_hsRecField . updName) <$> rec_flds
634637 dotdot =
635638 case rec_dotdot of
636639 Just {} -> [txt ".."]
@@ -639,8 +642,17 @@ p_hsExpr = \case
639642 RecordUpd {..} -> do
640643 located rupd_expr p_hsExpr
641644 breakpoint
645+ let updName f = f {
646+ hsRecFieldLbl = case unLoc $ hsRecFieldLbl f of
647+ Ambiguous _ n -> n
648+ Unambiguous _ n -> n
649+ XAmbiguousFieldOcc _ -> notImplemented "XAmbiguousFieldOcc"
650+ }
642651 inci . braces . sitcc $
643− sep (comma >> breakpoint) (sitcc . located' p_hsRecField) rupd_flds
652+ sep
653+ (comma >> breakpoint)
654+ (sitcc . located' (p_hsRecField . updName))
655+ rupd_flds
644656 ExprWithTySig affix x -> sitcc $ do
645657 located x p_hsExpr
646658 breakpoint