[commit: ghc] wip/orf-reboot: Clarify a corner case with an additional test (cd4fe28)

git at git.haskell.org git at git.haskell.org
Mon Oct 12 06:36:51 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/orf-reboot
Link       : http://ghc.haskell.org/trac/ghc/changeset/cd4fe2818df8f25e10d4e84a5a2a069517114508/ghc

>---------------------------------------------------------------

commit cd4fe2818df8f25e10d4e84a5a2a069517114508
Author: Adam Gundry <adam at well-typed.com>
Date:   Mon Oct 5 15:59:58 2015 +0100

    Clarify a corner case with an additional test


>---------------------------------------------------------------

cd4fe2818df8f25e10d4e84a5a2a069517114508
 compiler/basicTypes/Avail.hs                               |  8 ++++++--
 .../should_fail/OverloadedRecFldsFail10_A.hs               |  5 +++++
 .../should_fail/OverloadedRecFldsFail10_B.hs               |  6 ++++++
 .../should_fail/OverloadedRecFldsFail10_C.hs               |  6 ++++++
 testsuite/tests/overloadedrecflds/should_fail/all.T        |  5 +++++
 .../should_fail/overloadedrecfldsfail10.hs                 | 11 +++++++++++
 .../should_fail/overloadedrecfldsfail10.stderr             | 14 ++++++++++++++
 7 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/compiler/basicTypes/Avail.hs b/compiler/basicTypes/Avail.hs
index cc39625..26bf6ee 100644
--- a/compiler/basicTypes/Avail.hs
+++ b/compiler/basicTypes/Avail.hs
@@ -95,8 +95,12 @@ is possible to have
   AvailTC F [F, MkFInt, MkFBool]
     [FieldLabel "foo" True $sel:foo:MkFInt, FieldLabel "foo" False foo].
 
-AMG TODO: but if we do this with two identically-named things,
-something must go wrong on re-export?
+If the two data instances are defined in different modules, both
+without `-XDuplicateRecordFields`, it will be impossible to export
+them from the same module (even with `-XDuplicateRecordfields`
+enabled), because they would be represented identically.  The
+workaround here is to enable `-XDuplicateRecordFields` on the defining
+modules.
 -}
 
 -- | Compare lexicographically
diff --git a/testsuite/tests/overloadedrecflds/should_fail/OverloadedRecFldsFail10_A.hs b/testsuite/tests/overloadedrecflds/should_fail/OverloadedRecFldsFail10_A.hs
new file mode 100644
index 0000000..9234882
--- /dev/null
+++ b/testsuite/tests/overloadedrecflds/should_fail/OverloadedRecFldsFail10_A.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE TypeFamilies #-}
+module OverloadedRecFldsFail10_A where
+
+data family F a
+data instance F Int = MkFInt { foo :: Int }
diff --git a/testsuite/tests/overloadedrecflds/should_fail/OverloadedRecFldsFail10_B.hs b/testsuite/tests/overloadedrecflds/should_fail/OverloadedRecFldsFail10_B.hs
new file mode 100644
index 0000000..9cb346a
--- /dev/null
+++ b/testsuite/tests/overloadedrecflds/should_fail/OverloadedRecFldsFail10_B.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE TypeFamilies #-}
+module OverloadedRecFldsFail10_B (F(..)) where
+
+import OverloadedRecFldsFail10_A hiding (foo)
+
+data instance F Bool = MkFBool { foo :: Int }
diff --git a/testsuite/tests/overloadedrecflds/should_fail/OverloadedRecFldsFail10_C.hs b/testsuite/tests/overloadedrecflds/should_fail/OverloadedRecFldsFail10_C.hs
new file mode 100644
index 0000000..700ed2b
--- /dev/null
+++ b/testsuite/tests/overloadedrecflds/should_fail/OverloadedRecFldsFail10_C.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE DuplicateRecordFields, TypeFamilies #-}
+module OverloadedRecFldsFail10_C (F(..)) where
+
+import OverloadedRecFldsFail10_A
+
+data instance F Char = MkFChar { foo :: Char }
diff --git a/testsuite/tests/overloadedrecflds/should_fail/all.T b/testsuite/tests/overloadedrecflds/should_fail/all.T
index 1447985..7bce887 100644
--- a/testsuite/tests/overloadedrecflds/should_fail/all.T
+++ b/testsuite/tests/overloadedrecflds/should_fail/all.T
@@ -11,3 +11,8 @@ test('overloadedrecfldsfail06',
 test('overloadedrecfldsfail07', normal, compile_fail, [''])
 test('overloadedrecfldsfail08', normal, compile_fail, [''])
 test('overloadedrecfldsfail09', normal, compile_fail, [''])
+test('overloadedrecfldsfail10',
+     extra_clean([ 'OverloadedRecFldsFail10_A.hi', 'OverloadedRecFldsFail10_A.o'
+                 , 'OverloadedRecFldsFail10_B.hi', 'OverloadedRecFldsFail10_B.o'
+                 , 'OverloadedRecFldsFail10_C.hi', 'OverloadedRecFldsFail10_C.o']),
+     multimod_compile_fail, ['overloadedrecfldsfail10', ''])
diff --git a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail10.hs b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail10.hs
new file mode 100644
index 0000000..ccb25d3
--- /dev/null
+++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail10.hs
@@ -0,0 +1,11 @@
+-- Modules A and B both declare F(foo)
+-- Module C declares F($sel:foo:MkFChar) but exports A.F(foo) as well
+-- Thus we can't export F(..) even with DuplicateRecordFields enabled
+
+{-# LANGUAGE DuplicateRecordFields #-}
+module Main (main, F(..)) where
+
+import OverloadedRecFldsFail10_B
+import OverloadedRecFldsFail10_C
+
+main = return ()
diff --git a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail10.stderr b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail10.stderr
new file mode 100644
index 0000000..9d8e8bd
--- /dev/null
+++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail10.stderr
@@ -0,0 +1,14 @@
+[1 of 4] Compiling OverloadedRecFldsFail10_A ( OverloadedRecFldsFail10_A.hs, OverloadedRecFldsFail10_A.o )
+[2 of 4] Compiling OverloadedRecFldsFail10_C ( OverloadedRecFldsFail10_C.hs, OverloadedRecFldsFail10_C.o )
+[3 of 4] Compiling OverloadedRecFldsFail10_B ( OverloadedRecFldsFail10_B.hs, OverloadedRecFldsFail10_B.o )
+[4 of 4] Compiling Main             ( overloadedrecfldsfail10.hs, overloadedrecfldsfail10.o )
+
+overloadedrecfldsfail10.hs:6:20: error:
+    Conflicting exports for ‘foo’:
+       ‘F(..)’ exports ‘OverloadedRecFldsFail10_B.foo’
+         imported from ‘OverloadedRecFldsFail10_B’ at overloadedrecfldsfail10.hs:8:1-32
+         (and originally defined at OverloadedRecFldsFail10_B.hs:6:34-36)
+       ‘F(..)’ exports ‘OverloadedRecFldsFail10_C.foo’
+         imported from ‘OverloadedRecFldsFail10_C’ at overloadedrecfldsfail10.hs:9:1-32
+         (and originally defined in ‘OverloadedRecFldsFail10_A’
+            at OverloadedRecFldsFail10_A.hs:5:32-34)



More information about the ghc-commits mailing list