Commit b5c94262 authored by thomasw's avatar thomasw Committed by Ben Gamari

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
parent e78841b5
...@@ -1654,25 +1654,26 @@ badImportItemErrDataCon :: OccName ...@@ -1654,25 +1654,26 @@ badImportItemErrDataCon :: OccName
-> ImpDeclSpec -> ImpDeclSpec
-> IE RdrName -> IE RdrName
-> SDoc -> SDoc
badImportItemErrDataCon dataType is_boot decl_spec ie badImportItemErrDataCon dataType_occ is_boot decl_spec ie
= vcat [ ptext (sLit "In module") = vcat [ ptext (sLit "In module")
<+> quotes (ppr (is_mod decl_spec)) <+> quotes (ppr (is_mod decl_spec))
<+> source_import <> colon <+> source_import <> colon
, nest 2 $ quotes datacon , nest 2 $ quotes datacon
<+> ptext (sLit "is a data constructor of") <+> ptext (sLit "is a data constructor of")
<+> quotes (ppr dataType) <+> quotes dataType
, ptext (sLit "To import it use") , ptext (sLit "To import it use")
, nest 2 $ quotes (ptext (sLit "import")) , nest 2 $ quotes (ptext (sLit "import"))
<+> ppr (is_mod decl_spec) <+> ppr (is_mod decl_spec)
<> parens_sp (ppr dataType <> parens_sp datacon) <> parens_sp (dataType <> parens_sp datacon)
, ptext (sLit "or") , ptext (sLit "or")
, nest 2 $ quotes (ptext (sLit "import")) , nest 2 $ quotes (ptext (sLit "import"))
<+> ppr (is_mod decl_spec) <+> ppr (is_mod decl_spec)
<> parens_sp (ppr dataType <> ptext (sLit "(..)")) <> parens_sp (dataType <> ptext (sLit "(..)"))
] ]
where where
datacon_occ = rdrNameOcc $ ieName ie datacon_occ = rdrNameOcc $ ieName ie
datacon = parenSymOcc datacon_occ (ppr datacon_occ) datacon = parenSymOcc datacon_occ (ppr datacon_occ)
dataType = parenSymOcc dataType_occ (ppr dataType_occ)
source_import | is_boot = ptext (sLit "(hi-boot interface)") source_import | is_boot = ptext (sLit "(hi-boot interface)")
| otherwise = Outputable.empty | otherwise = Outputable.empty
parens_sp d = parens (space <> d <> space) -- T( f,g ) parens_sp d = parens (space <> d <> space) -- T( f,g )
......
module T10668 where
import Data.Type.Equality(Refl)
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( (:~:)(..) )
...@@ -134,3 +134,4 @@ test('T9032', ...@@ -134,3 +134,4 @@ test('T9032',
run_command, run_command,
['$MAKE -s --no-print-directory T9032']) ['$MAKE -s --no-print-directory T9032'])
test('T10618', normal, compile_fail, ['']) test('T10618', normal, compile_fail, [''])
test('T10668', normal, compile_fail, [''])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment