[Git][ghc/ghc][master] parser: don't suggest ImportQualifiedPost when it is already enabled
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 0bf1d8c9 by Sasha Bogicevic at 2026-07-22T11:31:21-04:00 parser: don't suggest ImportQualifiedPost when it is already enabled -Wprepositive-qualified-module unconditionally attached a hint to enable ImportQualifiedPost, even when the extension was already on (as it is by default under GHC2021). Record the extension's state in the PsWarnImportPreQualified diagnostic and drop the hint when it is already enabled. Fixes #27380 - - - - - 8 changed files: - + changelog.d/27380 - compiler/GHC/Parser/Errors/Ppr.hs - compiler/GHC/Parser/Errors/Types.hs - compiler/GHC/Parser/PostProcess.hs - + testsuite/tests/module/T27380.hs - + testsuite/tests/module/T27380.stderr - testsuite/tests/module/all.T - testsuite/tests/module/mod184.stderr Changes: ===================================== changelog.d/27380 ===================================== @@ -0,0 +1,7 @@ +section: compiler +synopsis: Don't suggest enabling ``ImportQualifiedPost`` when it is already enabled. + The :ghc-flag:`-Wprepositive-qualified-module` warning no longer suggests + enabling the extension if it is already in effect (as it is by default + under GHC2021). +issues: #27380 +mrs: !16376 ===================================== compiler/GHC/Parser/Errors/Ppr.hs ===================================== @@ -113,7 +113,7 @@ instance Diagnostic PsMessage where <> if null prag then empty else text ":" <+> text prag PsWarnMisplacedPragma prag -> mkSimpleDecorated $ text "Misplaced" <+> pprFileHeaderPragmaType prag <+> text "pragma" - PsWarnImportPreQualified + PsWarnImportPreQualified _iqp_on -> mkSimpleDecorated $ text "Found" <+> quotes (text "qualified") <+> text "in prepositive position" @@ -603,7 +603,7 @@ instance Diagnostic PsMessage where PsWarnStarIsType -> WarningWithFlag Opt_WarnStarIsType PsWarnUnrecognisedPragma{} -> WarningWithFlag Opt_WarnUnrecognisedPragmas PsWarnMisplacedPragma{} -> WarningWithFlag Opt_WarnMisplacedPragmas - PsWarnImportPreQualified -> WarningWithFlag Opt_WarnPrepositiveQualifiedModule + PsWarnImportPreQualified{} -> WarningWithFlag Opt_WarnPrepositiveQualifiedModule PsWarnViewPatternSignatures{} -> WarningWithFlag Opt_WarnViewPatternSignatures PsErrLexer{} -> ErrorWithoutFlag PsErrCmmLexer -> ErrorWithoutFlag @@ -735,8 +735,10 @@ instance Diagnostic PsMessage where then noHints else [SuggestCorrectPragmaName suggestions] PsWarnMisplacedPragma{} -> [SuggestPlacePragmaInHeader] - PsWarnImportPreQualified -> [ SuggestQualifiedAfterModuleName - , suggestExtension LangExt.ImportQualifiedPost] + PsWarnImportPreQualified iqp_on | iqp_on -> [ SuggestQualifiedAfterModuleName ] + | otherwise -> [ SuggestQualifiedAfterModuleName + , suggestExtension LangExt.ImportQualifiedPost + ] PsWarnViewPatternSignatures{} -> [SuggestParenthesizePatternRHS] PsErrLexer{} -> noHints PsErrCmmLexer -> noHints ===================================== compiler/GHC/Parser/Errors/Types.hs ===================================== @@ -133,7 +133,7 @@ data PsMessage | PsWarnStarIsType -- | Pre qualified import with 'WarnPrepositiveQualifiedModule' enabled - | PsWarnImportPreQualified + | PsWarnImportPreQualified !Bool -- is 'ImportQualifiedPost' enabled? | PsWarnOperatorWhitespaceExtConflict !OperatorWhitespaceSymbol ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -1326,7 +1326,7 @@ checkImportDecl mPre mPost preLevel postLevel = do -- Warn if 'qualified' found in prepositive position and -- 'Opt_WarnPrepositiveQualifiedModule' is enabled. whenJust mPre $ \pre -> - warnPrepositiveQualifiedModule (tokenSpan pre) + warnPrepositiveQualifiedModule (tokenSpan pre) importQualifiedPostEnabled return (qualSpec, levelSpec) @@ -3498,9 +3498,9 @@ isImpExpQcWildcard _ = False ----------------------------------------------------------------------------- -- Warnings and failures -warnPrepositiveQualifiedModule :: SrcSpan -> P () -warnPrepositiveQualifiedModule span = - addPsMessage span PsWarnImportPreQualified +warnPrepositiveQualifiedModule :: SrcSpan -> Bool -> P () +warnPrepositiveQualifiedModule span qualifiedPostEnabled = + addPsMessage span $ PsWarnImportPreQualified qualifiedPostEnabled failNotEnabledImportQualifiedPost :: SrcSpan -> P () failNotEnabledImportQualifiedPost loc = ===================================== testsuite/tests/module/T27380.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE NoImportQualifiedPost #-} +{-# OPTIONS_GHC -Wprepositive-qualified-module #-} +-- Negative control for #27380: with the extension explicitly disabled, +-- the ImportQualifiedPost suggestion must still appear. +import qualified System.IO +main :: IO () +main = System.IO.print "hi" ===================================== testsuite/tests/module/T27380.stderr ===================================== @@ -0,0 +1,6 @@ +T27380.hs:5:8: warning: [GHC-07924] [-Wprepositive-qualified-module] + Found ‘qualified’ in prepositive position + Suggested fixes: + • Place ‘qualified’ after the module name. + • Perhaps you intended to use the ‘ImportQualifiedPost’ extension + ===================================== testsuite/tests/module/all.T ===================================== @@ -295,3 +295,4 @@ test('T21826', normal, compile_fail, ['']) test('T20007', normal, compile_fail, ['']) test('T25901_imp_plain_wc', normal, compile_fail, ['']) test('T25901_exp_plain_wc', normal, compile_fail, ['']) +test('T27380', normal, compile, ['']) ===================================== testsuite/tests/module/mod184.stderr ===================================== @@ -1,6 +1,4 @@ - mod184.hs:6:8: warning: [GHC-07924] [-Wprepositive-qualified-module] Found ‘qualified’ in prepositive position - Suggested fixes: - • Place ‘qualified’ after the module name. - • Perhaps you intended to use the ‘ImportQualifiedPost’ extension + Suggested fix: Place ‘qualified’ after the module name. + View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0bf1d8c98baea8bc6a5fd3a39c8668de... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0bf1d8c98baea8bc6a5fd3a39c8668de... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Marge Bot (@marge-bot)