[commit: ghc] ghc-7.10: Parenthesise TypeOperator in import hints (4275c4a)

git at git.haskell.org git at git.haskell.org
Thu Oct 22 15:08:36 UTC 2015


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

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/4275c4a72a7fafa3cf57a2f07231e4b6bca2e6b2/ghc

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

commit 4275c4a72a7fafa3cf57a2f07231e4b6bca2e6b2
Author: Thomas Winant <thomas.winant at cs.kuleuven.be>
Date:   Thu Jul 23 11:43:21 2015 +0200

    Parenthesise TypeOperator in import hints
    
    When a constructor was mistakenly imported directly instead of as a
    constructor of a data type, a hint will be shown on how to correctly
    import
    it. Just like the constructor, the data type should be surrounded in
    parentheses if it is an operator (TypeOperator in this case).
    
    Instead of:
    
        error:
            In module ‘Data.Type.Equality’:
              ‘Refl’ is a data constructor of ‘:~:’
            To import it use
              ‘import’ Data.Type.Equality( :~:( Refl ) )
            or
              ‘import’ Data.Type.Equality( :~:(..) )
    
    Print:
    
        error:
            In module ‘Data.Type.Equality’:
              ‘Refl’ is a data constructor of ‘(:~:)’
            To import it use
              ‘import’ Data.Type.Equality( (:~:)( Refl ) )
            or
              ‘import’ Data.Type.Equality( (:~:)(..) )
    
    Test Plan: pass new test
    
    Reviewers: austin, bgamari, simonpj
    
    Reviewed By: simonpj
    
    Subscribers: simonpj, thomie
    
    Differential Revision: https://phabricator.haskell.org/D1093
    
    GHC Trac Issues: #10668


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

4275c4a72a7fafa3cf57a2f07231e4b6bca2e6b2
 compiler/rename/RnNames.hs                       | 9 +++++----
 testsuite/tests/rename/should_fail/T10668.hs     | 3 +++
 testsuite/tests/rename/should_fail/T10668.stderr | 8 ++++++++
 testsuite/tests/rename/should_fail/all.T         | 1 +
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/compiler/rename/RnNames.hs b/compiler/rename/RnNames.hs
index 2818db8..58a743e 100644
--- a/compiler/rename/RnNames.hs
+++ b/compiler/rename/RnNames.hs
@@ -1631,25 +1631,26 @@ badImportItemErrDataCon :: OccName
                         -> ImpDeclSpec
                         -> IE RdrName
                         -> SDoc
-badImportItemErrDataCon dataType is_boot decl_spec ie
+badImportItemErrDataCon dataType_occ is_boot decl_spec ie
   = vcat [ ptext (sLit "In module")
              <+> quotes (ppr (is_mod decl_spec))
              <+> source_import <> colon
          , nest 2 $ quotes datacon
              <+> ptext (sLit "is a data constructor of")
-             <+> quotes (ppr dataType)
+             <+> quotes dataType
          , ptext (sLit "To import it use")
          , nest 2 $ quotes (ptext (sLit "import"))
              <+> ppr (is_mod decl_spec)
-             <> parens_sp (ppr dataType <> parens_sp datacon)
+             <> parens_sp (dataType <> parens_sp datacon)
          , ptext (sLit "or")
          , nest 2 $ quotes (ptext (sLit "import"))
              <+> ppr (is_mod decl_spec)
-             <> parens_sp (ppr dataType <> ptext (sLit "(..)"))
+             <> parens_sp (dataType <> ptext (sLit "(..)"))
          ]
   where
     datacon_occ = rdrNameOcc $ ieName ie
     datacon = parenSymOcc datacon_occ (ppr datacon_occ)
+    dataType = parenSymOcc dataType_occ (ppr dataType_occ)
     source_import | is_boot       = ptext (sLit "(hi-boot interface)")
                   | otherwise     = Outputable.empty
     parens_sp d = parens (space <> d <> space)  -- T( f,g )
diff --git a/testsuite/tests/rename/should_fail/T10668.hs b/testsuite/tests/rename/should_fail/T10668.hs
new file mode 100644
index 0000000..111637b
--- /dev/null
+++ b/testsuite/tests/rename/should_fail/T10668.hs
@@ -0,0 +1,3 @@
+module T10668 where
+
+import Data.Type.Equality(Refl)
diff --git a/testsuite/tests/rename/should_fail/T10668.stderr b/testsuite/tests/rename/should_fail/T10668.stderr
new file mode 100644
index 0000000..8c96fad
--- /dev/null
+++ b/testsuite/tests/rename/should_fail/T10668.stderr
@@ -0,0 +1,8 @@
+
+T10668.hs:3:27: error:
+    In module ‘Data.Type.Equality’:
+      ‘Refl’ is a data constructor of ‘(:~:)’
+    To import it use
+      ‘import’ Data.Type.Equality( (:~:)( Refl ) )
+    or
+      ‘import’ Data.Type.Equality( (:~:)(..) )
diff --git a/testsuite/tests/rename/should_fail/all.T b/testsuite/tests/rename/should_fail/all.T
index 2aeee2f..69ad1a3 100644
--- a/testsuite/tests/rename/should_fail/all.T
+++ b/testsuite/tests/rename/should_fail/all.T
@@ -132,3 +132,4 @@ test('T9032',
      normal,
      run_command,
      ['$MAKE -s --no-print-directory T9032'])
+test('T10668', normal, compile_fail, [''])



More information about the ghc-commits mailing list