diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2020-10-13 02:39:12 +0300 |
---|---|---|
committer | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2020-10-17 13:38:35 -0400 |
commit | 02f5b644d89eaf7b356eb6728200f948dfb32f1b (patch) | |
tree | 4a27b63efbe4d89bc1e15d1b15afd5935beb2dce /compiler/GHC/Parser/Errors/Ppr.hs | |
parent | b02a9ea79dddd98f6bbb42e1652d7ea38db7d55e (diff) | |
download | haskell-wip/warn-operator-whitespace.tar.gz |
Implement -Woperator-whitespace (#18834)wip/warn-operator-whitespace
This patch implements two related warnings:
-Woperator-whitespace-ext-conflict
warns on uses of infix operators that would be parsed
differently were a particular GHC extension enabled
-Woperator-whitespace
warns on prefix, suffix, and tight infix uses of infix
operators
Updates submodules: haddock, containers.
Diffstat (limited to 'compiler/GHC/Parser/Errors/Ppr.hs')
-rw-r--r-- | compiler/GHC/Parser/Errors/Ppr.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/compiler/GHC/Parser/Errors/Ppr.hs b/compiler/GHC/Parser/Errors/Ppr.hs index f99cac90a4..c4b411b1c3 100644 --- a/compiler/GHC/Parser/Errors/Ppr.hs +++ b/compiler/GHC/Parser/Errors/Ppr.hs @@ -102,6 +102,34 @@ pprWarning = \case <+> text "after the module name instead." $$ text "To allow this, enable language extension 'ImportQualifiedPost'" + WarnOperatorWhitespaceExtConflict loc sym + -> mkParserWarn Opt_WarnOperatorWhitespaceExtConflict loc $ + let mk_prefix_msg operator_symbol extension_name syntax_meaning = + text "The prefix use of a" <+> quotes (text operator_symbol) + <+> text "would denote" <+> text syntax_meaning + $$ nest 2 (text "were the" <+> text extension_name <+> text "extension enabled.") + $$ text "Suggested fix: add whitespace after the" + <+> quotes (text operator_symbol) <> char '.' + in + case sym of + OperatorWhitespaceSymbol_PrefixPercent -> mk_prefix_msg "%" "LinearTypes" "a multiplicity annotation" + OperatorWhitespaceSymbol_PrefixDollar -> mk_prefix_msg "$" "TemplateHaskell" "an untyped splice" + OperatorWhitespaceSymbol_PrefixDollarDollar -> mk_prefix_msg "$$" "TemplateHaskell" "a typed splice" + + + WarnOperatorWhitespace loc sym occ_type + -> mkParserWarn Opt_WarnOperatorWhitespace loc $ + let mk_msg occ_type_str = + text "The" <+> text occ_type_str <+> text "use of a" <+> quotes (ftext sym) + <+> text "might be repurposed as special syntax" + $$ nest 2 (text "by a future language extension.") + $$ text "Suggested fix: add whitespace around it." + in + case occ_type of + OperatorWhitespaceOccurrence_Prefix -> mk_msg "prefix" + OperatorWhitespaceOccurrence_Suffix -> mk_msg "suffix" + OperatorWhitespaceOccurrence_TightInfix -> mk_msg "tight infix" + pprError :: Error -> ErrMsg pprError err = mkParserErr (errLoc err) $ vcat (pp_err (errDesc err) : map pp_hint (errHints err)) |