diff options
author | Thomas Winant <thomas.winant@cs.kuleuven.be> | 2015-07-23 11:43:21 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-10-22 14:26:46 +0200 |
commit | 4275c4a72a7fafa3cf57a2f07231e4b6bca2e6b2 (patch) | |
tree | c264b4648f9e2020ba4dd8fcc0f972f098a67ab3 | |
parent | 211eac24e15471017b20a2446fbb92525f26c83d (diff) | |
download | haskell-4275c4a72a7fafa3cf57a2f07231e4b6bca2e6b2.tar.gz |
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
-rw-r--r-- | compiler/rename/RnNames.hs | 9 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/T10668.hs | 3 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/T10668.stderr | 8 | ||||
-rw-r--r-- | 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 2818db82e4..58a743e08e 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 0000000000..111637b19b --- /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 0000000000..8c96fad1a8 --- /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 2aeee2f6fc..69ad1a31ac 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, ['']) |