From e660f4bf546e90fb6719ad268ca3daaecdce4b82 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Sat, 8 Oct 2016 10:06:01 +0100 Subject: Rework renaming of children in export lists. The target of this patch is exports such as: ``` module Foo ( T(A, B, C) ) where ``` Essentially this patch makes sure that we use the correct lookup functions in order to lookup the names in parent-children export lists. This change highlighted the complexity of this small part of GHC which accounts for the scale. This change was motivated by wanting to remove the `PatternSynonym` constructor from `Parent`. As with all these things, it quickly spiraled out of control into a much larger refactor. Reviewers: simonpj, goldfire, bgamari, austin Subscribers: adamgundry, thomie Differential Revision: https://phabricator.haskell.org/D2179 GHC Trac Issues: #11970 --- testsuite/tests/module/MultiExport.hs | 6 ++++++ testsuite/tests/module/MultiExport.stderr | 3 +++ testsuite/tests/module/T11970.hs | 19 +++++++++++++++++++ testsuite/tests/module/T11970.stderr | 12 ++++++++++++ testsuite/tests/module/T11970A.hs | 3 +++ testsuite/tests/module/T11970A.stderr | 5 +++++ testsuite/tests/module/T11970A1.hs | 3 +++ testsuite/tests/module/T11970B.hs | 5 +++++ testsuite/tests/module/T11970B.stderr | 5 +++++ testsuite/tests/module/all.T | 4 ++++ testsuite/tests/module/mod10.stderr | 4 +++- testsuite/tests/module/mod17.stderr | 8 +++++--- testsuite/tests/module/mod3.stderr | 8 +++++--- testsuite/tests/module/mod4.stderr | 7 ++++--- .../tests/overloadedrecflds/should_fail/NoParent.hs | 6 ++++++ .../overloadedrecflds/should_fail/NoParent.stderr | 6 ++++++ testsuite/tests/overloadedrecflds/should_fail/all.T | 1 + .../tests/patsyn/should_fail/export-class.stderr | 5 +++-- 18 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 testsuite/tests/module/MultiExport.hs create mode 100644 testsuite/tests/module/MultiExport.stderr create mode 100644 testsuite/tests/module/T11970.hs create mode 100644 testsuite/tests/module/T11970.stderr create mode 100644 testsuite/tests/module/T11970A.hs create mode 100644 testsuite/tests/module/T11970A.stderr create mode 100644 testsuite/tests/module/T11970A1.hs create mode 100644 testsuite/tests/module/T11970B.hs create mode 100644 testsuite/tests/module/T11970B.stderr create mode 100644 testsuite/tests/overloadedrecflds/should_fail/NoParent.hs create mode 100644 testsuite/tests/overloadedrecflds/should_fail/NoParent.stderr (limited to 'testsuite/tests') diff --git a/testsuite/tests/module/MultiExport.hs b/testsuite/tests/module/MultiExport.hs new file mode 100644 index 0000000000..4f8079ee81 --- /dev/null +++ b/testsuite/tests/module/MultiExport.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE PatternSynonyms #-} +module Foo ( A(x, x) ) where + +data A = A Int + +pattern Pattern{x} = A x diff --git a/testsuite/tests/module/MultiExport.stderr b/testsuite/tests/module/MultiExport.stderr new file mode 100644 index 0000000000..d117b69c8b --- /dev/null +++ b/testsuite/tests/module/MultiExport.stderr @@ -0,0 +1,3 @@ + +MultiExport.hs:2:14: warning: [-Wduplicate-exports (in -Wdefault)] + ‘x’ is exported by ‘A(x, x)’ and ‘A(x, x)’ diff --git a/testsuite/tests/module/T11970.hs b/testsuite/tests/module/T11970.hs new file mode 100644 index 0000000000..3c90c6913d --- /dev/null +++ b/testsuite/tests/module/T11970.hs @@ -0,0 +1,19 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE PatternSynonyms #-} + +module T11970(B(recSel), Foo((--.->)), C(C,P,x,Q, B, recSel)) where + +pattern D = Nothing + +newtype B = B { recSel :: Int } + +class Foo a where + type (--.->) a + +newtype C = C Int + +pattern P x = C x + +pattern Q{x} = C x diff --git a/testsuite/tests/module/T11970.stderr b/testsuite/tests/module/T11970.stderr new file mode 100644 index 0000000000..c6799a1898 --- /dev/null +++ b/testsuite/tests/module/T11970.stderr @@ -0,0 +1,12 @@ + +T11970.hs:6:40: error: + • The type constructor ‘C’ is not the parent of the data constructor ‘B’. + Data constructors can only be exported with their parent type constructor. + Parent: B + • In the export: C(C, P, x, Q, B, recSel) + +T11970.hs:6:40: error: + • The type constructor ‘C’ is not the parent of the record selector ‘recSel’. + Record selectors can only be exported with their parent type constructor. + Parent: B + • In the export: C(C, P, x, Q, B, recSel) diff --git a/testsuite/tests/module/T11970A.hs b/testsuite/tests/module/T11970A.hs new file mode 100644 index 0000000000..e9d6e95568 --- /dev/null +++ b/testsuite/tests/module/T11970A.hs @@ -0,0 +1,3 @@ +module T11970A ( Fail(a) ) where + +import T11970A1 ( Fail(a, b) ) diff --git a/testsuite/tests/module/T11970A.stderr b/testsuite/tests/module/T11970A.stderr new file mode 100644 index 0000000000..6b478a7335 --- /dev/null +++ b/testsuite/tests/module/T11970A.stderr @@ -0,0 +1,5 @@ +[1 of 2] Compiling T11970A1 ( T11970A1.hs, T11970A1.o ) +[2 of 2] Compiling T11970A ( T11970A.hs, T11970A.o ) + +T11970A.hs:3:1: warning: [-Wunused-imports (in -Wextra)] + The import of ‘Fail(b)’ from module ‘T11970A1’ is redundant diff --git a/testsuite/tests/module/T11970A1.hs b/testsuite/tests/module/T11970A1.hs new file mode 100644 index 0000000000..6c9c6d2a7a --- /dev/null +++ b/testsuite/tests/module/T11970A1.hs @@ -0,0 +1,3 @@ +module T11970A1 where + +data Fail = Fail { a :: Int, b :: Int } diff --git a/testsuite/tests/module/T11970B.hs b/testsuite/tests/module/T11970B.hs new file mode 100644 index 0000000000..70a091f141 --- /dev/null +++ b/testsuite/tests/module/T11970B.hs @@ -0,0 +1,5 @@ +module T11970B ( A(f) ) where + +data A = A + +f = A diff --git a/testsuite/tests/module/T11970B.stderr b/testsuite/tests/module/T11970B.stderr new file mode 100644 index 0000000000..240a5fa5f6 --- /dev/null +++ b/testsuite/tests/module/T11970B.stderr @@ -0,0 +1,5 @@ + +T11970B.hs:1:18: error: + • The type constructor ‘A’ is not the parent of the identifier ‘f’. + Identifiers can only be exported with their parent type constructor. + • In the export: A(f) diff --git a/testsuite/tests/module/all.T b/testsuite/tests/module/all.T index 89bdcc00e0..c7097b2dfc 100644 --- a/testsuite/tests/module/all.T +++ b/testsuite/tests/module/all.T @@ -350,3 +350,7 @@ test('T10233', extra_clean(['T01233a.hi', 'T01233a.o']), test('T11432', normal, compile_fail, ['']) test('T11432a', normal, compile_fail, ['']) test('T12026', normal, compile_fail, ['']) +test('T11970', normal, compile_fail, ['']) +test('T11970A', [], multimod_compile, ['T11970A','-Wunused-imports']) +test('T11970B', normal, compile_fail, ['']) +test('MultiExport', normal, compile, ['']) diff --git a/testsuite/tests/module/mod10.stderr b/testsuite/tests/module/mod10.stderr index dd08d880b3..1412b6af7d 100644 --- a/testsuite/tests/module/mod10.stderr +++ b/testsuite/tests/module/mod10.stderr @@ -1,2 +1,4 @@ -mod10.hs:2:10: Not in scope: type constructor or class ‘T’ +mod10.hs:2:10: error: + • Not in scope: type constructor or class ‘T’ + • In the export: T(K1) diff --git a/testsuite/tests/module/mod17.stderr b/testsuite/tests/module/mod17.stderr index 9dcf0e612f..91c4ff2731 100644 --- a/testsuite/tests/module/mod17.stderr +++ b/testsuite/tests/module/mod17.stderr @@ -1,4 +1,6 @@ -mod17.hs:2:10: - The export item ‘C(m1, m2, m3, Left)’ - attempts to export constructors or class methods that are not visible here +mod17.hs:2:10: error: + • The type constructor ‘C’ is not the parent of the data constructor ‘Left’. + Data constructors can only be exported with their parent type constructor. + Parent: Either + • In the export: C(m1, m2, m3, Left) diff --git a/testsuite/tests/module/mod3.stderr b/testsuite/tests/module/mod3.stderr index 6e7a88bd6d..c0c620e240 100644 --- a/testsuite/tests/module/mod3.stderr +++ b/testsuite/tests/module/mod3.stderr @@ -1,4 +1,6 @@ -mod3.hs:2:10: - The export item ‘T(K1)’ - attempts to export constructors or class methods that are not visible here +mod3.hs:2:10: error: + • The type constructor ‘T’ is not the parent of the data constructor ‘K1’. + Data constructors can only be exported with their parent type constructor. + Parent: T' + • In the export: T(K1) diff --git a/testsuite/tests/module/mod4.stderr b/testsuite/tests/module/mod4.stderr index 2391dadcdc..d9e8339740 100644 --- a/testsuite/tests/module/mod4.stderr +++ b/testsuite/tests/module/mod4.stderr @@ -1,4 +1,5 @@ -mod4.hs:2:10: - The export item ‘T(K1, K2)’ - attempts to export constructors or class methods that are not visible here +mod4.hs:2:10: error: + • Not in scope: data constructor ‘K2’ + Perhaps you meant ‘K1’ (line 3) + • In the export: T(K1, K2) diff --git a/testsuite/tests/overloadedrecflds/should_fail/NoParent.hs b/testsuite/tests/overloadedrecflds/should_fail/NoParent.hs new file mode 100644 index 0000000000..2d05c4758e --- /dev/null +++ b/testsuite/tests/overloadedrecflds/should_fail/NoParent.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE DuplicateRecordFields #-} +module NoParent (A(x)) where + +data A = A +data B = B { x :: Int } +data C = C { x :: String } diff --git a/testsuite/tests/overloadedrecflds/should_fail/NoParent.stderr b/testsuite/tests/overloadedrecflds/should_fail/NoParent.stderr new file mode 100644 index 0000000000..309536cede --- /dev/null +++ b/testsuite/tests/overloadedrecflds/should_fail/NoParent.stderr @@ -0,0 +1,6 @@ + +NoParent.hs:2:18: error: + • The type constructor ‘A’ is not the parent of the record selector ‘x’. + Record selectors can only be exported with their parent type constructor. + Parents: C, B + • In the export: A(x) diff --git a/testsuite/tests/overloadedrecflds/should_fail/all.T b/testsuite/tests/overloadedrecflds/should_fail/all.T index 362640539e..b7d1bff336 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/all.T +++ b/testsuite/tests/overloadedrecflds/should_fail/all.T @@ -30,3 +30,4 @@ test('T11167_ambiguous_fixity', extra_clean([ 'T11167_ambiguous_fixity_A.hi', 'T11167_ambiguous_fixity_A.o' , 'T11167_ambiguous_fixity_B.hi', 'T11167_ambiguous_fixity_B.o' ]), multimod_compile_fail, ['T11167_ambiguous_fixity', '']) +test('NoParent', normal, compile_fail, ['']) diff --git a/testsuite/tests/patsyn/should_fail/export-class.stderr b/testsuite/tests/patsyn/should_fail/export-class.stderr index 15be2deaf4..3f8031fb70 100644 --- a/testsuite/tests/patsyn/should_fail/export-class.stderr +++ b/testsuite/tests/patsyn/should_fail/export-class.stderr @@ -1,4 +1,5 @@ export-class.hs:3:13: error: - Pattern synonyms can be bundled only with datatypes. - In the export: MyClass(.., P) + • Pattern synonyms can be bundled only with datatypes. + • In the pattern synonym: P + In the export: MyClass(.., P) -- cgit v1.2.1