diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2018-03-23 11:40:02 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2018-03-23 11:40:02 -0400 |
commit | d5577f44eaf3b9dfdfc77828038782bf818c176a (patch) | |
tree | 447d2163367ece2e2801376e35d06490cfff779c /testsuite/tests/deriving | |
parent | 034c32f6b8abd15eb9affca972844d3c6842af69 (diff) | |
download | haskell-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 'testsuite/tests/deriving')
-rw-r--r-- | testsuite/tests/deriving/should_run/T14918.hs | 18 | ||||
-rw-r--r-- | testsuite/tests/deriving/should_run/T14918.stdout | 2 | ||||
-rw-r--r-- | testsuite/tests/deriving/should_run/all.T | 1 |
3 files changed, 21 insertions, 0 deletions
diff --git a/testsuite/tests/deriving/should_run/T14918.hs b/testsuite/tests/deriving/should_run/T14918.hs new file mode 100644 index 0000000000..2ad293724b --- /dev/null +++ b/testsuite/tests/deriving/should_run/T14918.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE MagicHash #-} +module Main where + +data T a = MkT { runT :: a, (##) :: a } deriving (Read, Show) +data T# a = MkT# { runT# :: a, (###) :: a } deriving (Read, Show) + +t1, t2 :: T Int +t1 = MkT (-1) 1 +t2 = read $ show t1 + +t1#, t2# :: T# Int +t1# = MkT# (-1) 1 +t2# = read $ show t1# + +main :: IO () +main = do + print t2 + print t2# diff --git a/testsuite/tests/deriving/should_run/T14918.stdout b/testsuite/tests/deriving/should_run/T14918.stdout new file mode 100644 index 0000000000..b85e2a219e --- /dev/null +++ b/testsuite/tests/deriving/should_run/T14918.stdout @@ -0,0 +1,2 @@ +MkT {runT = -1, (##) = 1} +MkT# {runT# = -1, (###) = 1} diff --git a/testsuite/tests/deriving/should_run/all.T b/testsuite/tests/deriving/should_run/all.T index c5605f627e..cf0cb922ed 100644 --- a/testsuite/tests/deriving/should_run/all.T +++ b/testsuite/tests/deriving/should_run/all.T @@ -45,3 +45,4 @@ test('T10598_bug', normal, compile_and_run, ['']) test('T10598_run', normal, compile_and_run, ['']) test('T11535', when(opsys('mingw32'), expect_broken_for(12210, ['ghci'])), compile_and_run, ['']) +test('T14918', normal, compile_and_run, ['']) |