diff options
author | Shayne Fletcher <shayne.fletcher@digitalasset.com> | 2019-05-07 17:35:50 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-05-08 15:29:01 -0400 |
commit | ed5f858b8484a207e28baf9cbec4c60de1c86187 (patch) | |
tree | 4dfe0b1ff3970bf2cac267299251e803f7ced7e8 /compiler/parser/RdrHsSyn.hs | |
parent | 0eeb4cfad732d0b9b278c2274cb6db9633f9d3b5 (diff) | |
download | haskell-ed5f858b8484a207e28baf9cbec4c60de1c86187.tar.gz |
Implement ImportQualifiedPost
Diffstat (limited to 'compiler/parser/RdrHsSyn.hs')
-rw-r--r-- | compiler/parser/RdrHsSyn.hs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs index 156931dc9f..490fed0384 100644 --- a/compiler/parser/RdrHsSyn.hs +++ b/compiler/parser/RdrHsSyn.hs @@ -49,6 +49,7 @@ module RdrHsSyn ( -- Bunch of functions in the parser monad for -- checking and constructing values + checkImportDecl, checkExpBlockArguments, checkPrecP, -- Int -> P Int checkContext, -- HsType -> P HsContext @@ -81,7 +82,10 @@ module RdrHsSyn ( -- Warnings and errors warnStarIsType, + warnPrepositiveQualifiedModule, failOpFewArgs, + failOpNotEnabledImportQualifiedPost, + failOpImportQualifiedTwice, SumOrTuple (..), @@ -1051,6 +1055,31 @@ checkNoDocs msg ty = go ty , text "on", msg, quotes (ppr t) ] go _ = pure () +checkImportDecl :: Maybe (Located Token) + -> Maybe (Located Token) + -> P () +checkImportDecl mPre mPost = do + let whenJust mg f = maybe (pure ()) f mg + + importQualifiedPostEnabled <- getBit ImportQualifiedPostBit + + -- Error if 'qualified' found in postpostive position and + -- 'ImportQualifiedPost' is not in effect. + whenJust mPost $ \post -> + when (not importQualifiedPostEnabled) $ + failOpNotEnabledImportQualifiedPost (getLoc post) + + -- Error if 'qualified' occurs in both pre and postpositive + -- positions. + whenJust mPost $ \post -> + when (isJust mPre) $ + failOpImportQualifiedTwice (getLoc post) + + -- Warn if 'qualified' found in prepositive position and + -- 'Opt_WarnPrepositiveQualifiedModule' is enabled. + whenJust mPre $ \pre -> + warnPrepositiveQualifiedModule (getLoc pre) + -- ------------------------------------------------------------------------- -- Checking Patterns. @@ -2945,6 +2974,27 @@ isImpExpQcWildcard _ = False ----------------------------------------------------------------------------- -- Warnings and failures +warnPrepositiveQualifiedModule :: SrcSpan -> P () +warnPrepositiveQualifiedModule span = + addWarning Opt_WarnPrepositiveQualifiedModule span msg + where + msg = text "Found" <+> quotes (text "qualified") + <+> text "in prepositive position" + $$ text "Suggested fix: place " <+> quotes (text "qualified") + <+> text "after the module name instead." + +failOpNotEnabledImportQualifiedPost :: SrcSpan -> P () +failOpNotEnabledImportQualifiedPost loc = addError loc msg + where + msg = text "Found" <+> quotes (text "qualified") + <+> text "in postpositive position. " + $$ text "To allow this, enable language extension 'ImportQualifiedPost'" + +failOpImportQualifiedTwice :: SrcSpan -> P () +failOpImportQualifiedTwice loc = addError loc msg + where + msg = text "Multiple occurences of 'qualified'" + warnStarIsType :: SrcSpan -> P () warnStarIsType span = addWarning Opt_WarnStarIsType span msg where |