Sasha Bogicevic pushed to branch wip/27380 at Glasgow Haskell Compiler / GHC
Commits:
-
9c420942
by Sasha Bogicevic at 2026-07-19T21:37:28+02:00
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:
| 1 | +section: compiler
|
|
| 2 | +synopsis: Don't suggest enabling ``ImportQualifiedPost`` when it is already enabled.
|
|
| 3 | + The :ghc-flag:`-Wprepositive-qualified-module` warning no longer suggests
|
|
| 4 | + enabling the extension if it is already in effect (as it is by default
|
|
| 5 | + under GHC2021).
|
|
| 6 | +issues: #27380
|
|
| 7 | +mrs: !16376 |
| ... | ... | @@ -113,7 +113,7 @@ instance Diagnostic PsMessage where |
| 113 | 113 | <> if null prag then empty else text ":" <+> text prag
|
| 114 | 114 | PsWarnMisplacedPragma prag
|
| 115 | 115 | -> mkSimpleDecorated $ text "Misplaced" <+> pprFileHeaderPragmaType prag <+> text "pragma"
|
| 116 | - PsWarnImportPreQualified
|
|
| 116 | + PsWarnImportPreQualified _iqp_on
|
|
| 117 | 117 | -> mkSimpleDecorated $
|
| 118 | 118 | text "Found" <+> quotes (text "qualified")
|
| 119 | 119 | <+> text "in prepositive position"
|
| ... | ... | @@ -603,7 +603,7 @@ instance Diagnostic PsMessage where |
| 603 | 603 | PsWarnStarIsType -> WarningWithFlag Opt_WarnStarIsType
|
| 604 | 604 | PsWarnUnrecognisedPragma{} -> WarningWithFlag Opt_WarnUnrecognisedPragmas
|
| 605 | 605 | PsWarnMisplacedPragma{} -> WarningWithFlag Opt_WarnMisplacedPragmas
|
| 606 | - PsWarnImportPreQualified -> WarningWithFlag Opt_WarnPrepositiveQualifiedModule
|
|
| 606 | + PsWarnImportPreQualified{} -> WarningWithFlag Opt_WarnPrepositiveQualifiedModule
|
|
| 607 | 607 | PsWarnViewPatternSignatures{} -> WarningWithFlag Opt_WarnViewPatternSignatures
|
| 608 | 608 | PsErrLexer{} -> ErrorWithoutFlag
|
| 609 | 609 | PsErrCmmLexer -> ErrorWithoutFlag
|
| ... | ... | @@ -735,8 +735,10 @@ instance Diagnostic PsMessage where |
| 735 | 735 | then noHints
|
| 736 | 736 | else [SuggestCorrectPragmaName suggestions]
|
| 737 | 737 | PsWarnMisplacedPragma{} -> [SuggestPlacePragmaInHeader]
|
| 738 | - PsWarnImportPreQualified -> [ SuggestQualifiedAfterModuleName
|
|
| 739 | - , suggestExtension LangExt.ImportQualifiedPost]
|
|
| 738 | + PsWarnImportPreQualified iqp_on | iqp_on -> [ SuggestQualifiedAfterModuleName ]
|
|
| 739 | + | otherwise -> [ SuggestQualifiedAfterModuleName
|
|
| 740 | + , suggestExtension LangExt.ImportQualifiedPost
|
|
| 741 | + ]
|
|
| 740 | 742 | PsWarnViewPatternSignatures{} -> [SuggestParenthesizePatternRHS]
|
| 741 | 743 | PsErrLexer{} -> noHints
|
| 742 | 744 | PsErrCmmLexer -> noHints
|
| ... | ... | @@ -133,7 +133,7 @@ data PsMessage |
| 133 | 133 | | PsWarnStarIsType
|
| 134 | 134 | |
| 135 | 135 | -- | Pre qualified import with 'WarnPrepositiveQualifiedModule' enabled
|
| 136 | - | PsWarnImportPreQualified
|
|
| 136 | + | PsWarnImportPreQualified !Bool -- is 'ImportQualifiedPost' enabled?
|
|
| 137 | 137 | |
| 138 | 138 | | PsWarnOperatorWhitespaceExtConflict !OperatorWhitespaceSymbol
|
| 139 | 139 |
| ... | ... | @@ -1327,7 +1327,7 @@ checkImportDecl mPre mPost preLevel postLevel = do |
| 1327 | 1327 | -- Warn if 'qualified' found in prepositive position and
|
| 1328 | 1328 | -- 'Opt_WarnPrepositiveQualifiedModule' is enabled.
|
| 1329 | 1329 | whenJust mPre $ \pre ->
|
| 1330 | - warnPrepositiveQualifiedModule (tokenSpan pre)
|
|
| 1330 | + warnPrepositiveQualifiedModule (tokenSpan pre) importQualifiedPostEnabled
|
|
| 1331 | 1331 | |
| 1332 | 1332 | return (qualSpec, levelSpec)
|
| 1333 | 1333 | |
| ... | ... | @@ -3499,9 +3499,9 @@ isImpExpQcWildcard _ = False |
| 3499 | 3499 | -----------------------------------------------------------------------------
|
| 3500 | 3500 | -- Warnings and failures
|
| 3501 | 3501 | |
| 3502 | -warnPrepositiveQualifiedModule :: SrcSpan -> P ()
|
|
| 3503 | -warnPrepositiveQualifiedModule span =
|
|
| 3504 | - addPsMessage span PsWarnImportPreQualified
|
|
| 3502 | +warnPrepositiveQualifiedModule :: SrcSpan -> Bool -> P ()
|
|
| 3503 | +warnPrepositiveQualifiedModule span qualifiedPostEnabled =
|
|
| 3504 | + addPsMessage span $ PsWarnImportPreQualified qualifiedPostEnabled
|
|
| 3505 | 3505 | |
| 3506 | 3506 | failNotEnabledImportQualifiedPost :: SrcSpan -> P ()
|
| 3507 | 3507 | failNotEnabledImportQualifiedPost loc =
|
| 1 | +{-# LANGUAGE NoImportQualifiedPost #-}
|
|
| 2 | +{-# OPTIONS_GHC -Wprepositive-qualified-module #-}
|
|
| 3 | +-- Negative control for #27380: with the extension explicitly disabled,
|
|
| 4 | +-- the ImportQualifiedPost suggestion must still appear.
|
|
| 5 | +import qualified System.IO
|
|
| 6 | +main :: IO ()
|
|
| 7 | +main = System.IO.print "hi" |
| 1 | +T27380.hs:5:8: warning: [GHC-07924] [-Wprepositive-qualified-module]
|
|
| 2 | + Found ‘qualified’ in prepositive position
|
|
| 3 | + Suggested fixes:
|
|
| 4 | + • Place ‘qualified’ after the module name.
|
|
| 5 | + • Perhaps you intended to use the ‘ImportQualifiedPost’ extension
|
|
| 6 | + |
| ... | ... | @@ -295,3 +295,4 @@ test('T21826', normal, compile_fail, ['']) |
| 295 | 295 | test('T20007', normal, compile_fail, [''])
|
| 296 | 296 | test('T25901_imp_plain_wc', normal, compile_fail, [''])
|
| 297 | 297 | test('T25901_exp_plain_wc', normal, compile_fail, [''])
|
| 298 | +test('T27380', normal, compile, ['']) |
| 1 | - |
|
| 2 | 1 | mod184.hs:6:8: warning: [GHC-07924] [-Wprepositive-qualified-module]
|
| 3 | 2 | Found ‘qualified’ in prepositive position
|
| 4 | - Suggested fixes:
|
|
| 5 | - • Place ‘qualified’ after the module name.
|
|
| 6 | - • Perhaps you intended to use the ‘ImportQualifiedPost’ extension |
|
| 3 | + Suggested fix: Place ‘qualified’ after the module name.
|
|
| 4 | + |