Commit 5692643c authored by thomie's avatar thomie Committed by Austin Seipp
Browse files

Show record construction/update without parens

Summary:
The 2010 report mentions:
"The result of `show` is a syntactically correct Haskell expression ...
Parenthesis are only added where needed, //ignoring associativity//".

Reviewers: austin

Reviewed By: austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D669

GHC Trac Issues: #2530
parent d2e6a3b5
...@@ -692,7 +692,7 @@ ppr_expr (RecordCon con_id _ rbinds) ...@@ -692,7 +692,7 @@ ppr_expr (RecordCon con_id _ rbinds)
= hang (ppr con_id) 2 (ppr rbinds) = hang (ppr con_id) 2 (ppr rbinds)
ppr_expr (RecordUpd aexp rbinds _ _ _) ppr_expr (RecordUpd aexp rbinds _ _ _)
= hang (pprParendExpr aexp) 2 (ppr rbinds) = hang (pprLExpr aexp) 2 (ppr rbinds)
ppr_expr (ExprWithTySig expr sig _) ppr_expr (ExprWithTySig expr sig _)
= hang (nest 2 (ppr_lexpr expr) <+> dcolon) = hang (nest 2 (ppr_lexpr expr) <+> dcolon)
...@@ -803,6 +803,8 @@ hsExprNeedsParens (HsIPVar {}) = False ...@@ -803,6 +803,8 @@ hsExprNeedsParens (HsIPVar {}) = False
hsExprNeedsParens (ExplicitTuple {}) = False hsExprNeedsParens (ExplicitTuple {}) = False
hsExprNeedsParens (ExplicitList {}) = False hsExprNeedsParens (ExplicitList {}) = False
hsExprNeedsParens (ExplicitPArr {}) = False hsExprNeedsParens (ExplicitPArr {}) = False
hsExprNeedsParens (RecordCon {}) = False
hsExprNeedsParens (RecordUpd {}) = False
hsExprNeedsParens (HsPar {}) = False hsExprNeedsParens (HsPar {}) = False
hsExprNeedsParens (HsBracket {}) = False hsExprNeedsParens (HsBracket {}) = False
hsExprNeedsParens (HsRnBracketOut {}) = False hsExprNeedsParens (HsRnBracketOut {}) = False
......
...@@ -1134,6 +1134,8 @@ gen_Show_binds get_fixity loc tycon ...@@ -1134,6 +1134,8 @@ gen_Show_binds get_fixity loc tycon
| nullary_con = -- skip the showParen junk... | nullary_con = -- skip the showParen junk...
ASSERT(null bs_needed) ASSERT(null bs_needed)
([nlWildPat, con_pat], mk_showString_app op_con_str) ([nlWildPat, con_pat], mk_showString_app op_con_str)
| record_syntax = -- skip showParen (#2530)
([a_Pat, con_pat], nlHsPar (nested_compose_Expr show_thingies))
| otherwise = | otherwise =
([a_Pat, con_pat], ([a_Pat, con_pat],
showParen_Expr (nlHsPar (genOpApp a_Expr ge_RDR showParen_Expr (nlHsPar (genOpApp a_Expr ge_RDR
......
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
(LiteralsTest.hs:15:3,ITequal,[=]), (LiteralsTest.hs:15:3,ITequal,[=]),
(LiteralsTest.hs:15:5-8,ITrational (FL {fl_text = "0.00", fl_value = 0 % 1}),[0.00]), (LiteralsTest.hs:15:5-8,ITrational FL {fl_text = "0.00", fl_value = 0 % 1},[0.00]),
(LiteralsTest.hs:17:1,ITsemi,[]), (LiteralsTest.hs:17:1,ITsemi,[]),
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
(LiteralsTest.hs:22:12,ITequal,[=]), (LiteralsTest.hs:22:12,ITequal,[=]),
(LiteralsTest.hs:22:14-18,ITprimfloat (FL {fl_text = "3.20", fl_value = 16 % 5}),[3.20#]), (LiteralsTest.hs:22:14-18,ITprimfloat FL {fl_text = "3.20", fl_value = 16 % 5},[3.20#]),
(LiteralsTest.hs:23:5,ITsemi,[]), (LiteralsTest.hs:23:5,ITsemi,[]),
...@@ -130,7 +130,7 @@ ...@@ -130,7 +130,7 @@
(LiteralsTest.hs:23:13,ITequal,[=]), (LiteralsTest.hs:23:13,ITequal,[=]),
(LiteralsTest.hs:23:15-21,ITprimdouble (FL {fl_text = "04.16", fl_value = 104 % 25}),[04.16##]), (LiteralsTest.hs:23:15-21,ITprimdouble FL {fl_text = "04.16", fl_value = 104 % 25},[04.16##]),
(LiteralsTest.hs:24:5,ITsemi,[]), (LiteralsTest.hs:24:5,ITsemi,[]),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment