summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/Read.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2018-03-23 11:40:02 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2018-03-23 11:40:02 -0400
commitd5577f44eaf3b9dfdfc77828038782bf818c176a (patch)
tree447d2163367ece2e2801376e35d06490cfff779c /libraries/base/GHC/Read.hs
parent034c32f6b8abd15eb9affca972844d3c6842af69 (diff)
downloadhaskell-d5577f44eaf3b9dfdfc77828038782bf818c176a.tar.gz
Special-case record fields ending with hash when deriving Read
Summary: In commit dbd81f7e86514498218572b9d978373b1699cc5b, a regression was inadvertently introduced which caused derived `Read` instances for record data types with fields ending in a `#` symbol (using `MagicHash`) would no longer parse on valid output. This is ultimately due to the same reasons as #5041, as we cannot parse a field name like `foo#` as a single identifier. We fix this issue by employing the same workaround as in #5041: first parse the identifier name `foo`, then then symbol `#`. This is accomplished by the new `readFieldHash` function in `GHC.Read`. This will likely warrant a `base-4.11.1.0` release. Test Plan: make test TEST=T14918 Reviewers: tdammers, hvr, bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #14918 Differential Revision: https://phabricator.haskell.org/D4502
Diffstat (limited to 'libraries/base/GHC/Read.hs')
-rw-r--r--libraries/base/GHC/Read.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/libraries/base/GHC/Read.hs b/libraries/base/GHC/Read.hs
index ad51c46ec5..f7870a2df1 100644
--- a/libraries/base/GHC/Read.hs
+++ b/libraries/base/GHC/Read.hs
@@ -37,6 +37,7 @@ module GHC.Read
, readListDefault, readListPrecDefault
, readNumber
, readField
+ , readFieldHash
, readSymField
-- Temporary
@@ -376,6 +377,22 @@ readField fieldName readVal = do
-- See Note [Why readField]
+-- | 'Read' parser for a record field, of the form @fieldName#=value@. That is,
+-- an alphanumeric identifier @fieldName@ followed by the symbol @#@. The
+-- second argument is a parser for the field value.
+--
+-- Note that 'readField' does not suffice for this purpose due to
+-- <https://ghc.haskell.org/trac/ghc/ticket/5041 Trac #5041>.
+readFieldHash :: String -> ReadPrec a -> ReadPrec a
+readFieldHash fieldName readVal = do
+ expectP (L.Ident fieldName)
+ expectP (L.Symbol "#")
+ expectP (L.Punc "=")
+ readVal
+{-# NOINLINE readFieldHash #-}
+
+-- See Note [Why readField]
+
-- | 'Read' parser for a symbol record field, of the form @(###)=value@ (where
-- @###@ is the field name). The field name must be a symbol (operator-style),
-- e.g. @(#)@. For regular (alphanumeric) field names, use 'readField'. The