Commit 1448f8ab authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

Show: Restore redundant parentheses around records

As discussed in #2530 we are going to continue to produce parentheses
here in order to preserve compatibility with previous GHC releases. It
was found that dropped parentheses would break some testsuites which
compared against output from Show. This has been documented in the users
guide.

This reverts commit 5692643c.

Test Plan: Validate

Reviewers: hvr, austin

Subscribers: thomie

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

GHC Trac Issues: #2350
parent ef653f1f
...@@ -791,8 +791,8 @@ ppr_expr (ExplicitPArr _ exprs) ...@@ -791,8 +791,8 @@ ppr_expr (ExplicitPArr _ exprs)
ppr_expr (RecordCon { rcon_con_name = con_id, rcon_flds = rbinds }) ppr_expr (RecordCon { rcon_con_name = con_id, rcon_flds = rbinds })
= hang (ppr con_id) 2 (ppr rbinds) = hang (ppr con_id) 2 (ppr rbinds)
ppr_expr (RecordUpd { rupd_expr = aexp, rupd_flds = rbinds }) ppr_expr (RecordUpd { rupd_expr = L _ aexp, rupd_flds = rbinds })
= hang (pprLExpr aexp) 2 (braces (fsep (punctuate comma (map ppr rbinds)))) = hang (pprParendExpr aexp) 2 (braces (fsep (punctuate comma (map 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)
...@@ -931,8 +931,6 @@ hsExprNeedsParens (HsOverLabel {}) = False ...@@ -931,8 +931,6 @@ hsExprNeedsParens (HsOverLabel {}) = 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
......
...@@ -1122,8 +1122,6 @@ gen_Show_binds get_fixity loc tycon ...@@ -1122,8 +1122,6 @@ 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 (genOpApp a_Expr ge_RDR showParen_Expr (genOpApp a_Expr ge_RDR
......
...@@ -223,6 +223,21 @@ Arbitrary-sized tuples ...@@ -223,6 +223,21 @@ Arbitrary-sized tuples
splitAt undefined [] = undefined splitAt undefined [] = undefined
``Show``\ ing records
The Haskell 2010 definition of ``Show`` stipulates that the rendered
string should only include parentheses which are necessary to unambiguously
parse the result. For historical reasons, ``Show`` instances derived by GHC
include parentheses around records despite the fact that record syntax
binds more tightly than function application; e.g., ::
data Hello = Hello { aField :: Int } deriving (Show)
-- GHC produces...
show (Just (Hello {aField=42})) == "Just (Hello {aField=42})"
-- whereas Haskell 2010 calls for...
show (Just (Hello {aField=42})) == "Just Hello {aField=42}"
``Read``\ ing integers ``Read``\ ing integers
GHC's implementation of the ``Read`` class for integral types GHC's implementation of the ``Read`` class for integral types
accepts hexadecimal and octal literals (the code in the Haskell 98 accepts hexadecimal and octal literals (the code in the Haskell 98
......
...@@ -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