git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add deprecation warning for import qualified syntax
commit42702e84a8a388cb17684570152ddeb5659b18bf authorGary Burgess <gary.burgess@gmail.com> dateSat 21 Nov 2015, 18:52 (11 years ago) parent17eaed5
12 files changed+28−18
psci/PSCi.hs+1−1 psci/Parser.hs+3−1 src/Language/PureScript/AST/Declarations.hs+2−1 src/Language/PureScript/CoreFn/Desugar.hs+1−1 src/Language/PureScript/Docs/ParseAndDesugar.hs+2−2 src/Language/PureScript/Errors.hs+6 src/Language/PureScript/Externs.hs+1−1 src/Language/PureScript/Make.hs+2−2 src/Language/PureScript/ModuleDependencies.hs+1−1 src/Language/PureScript/Parser/Declarations.hs+5−5 src/Language/PureScript/Sugar/Names.hs+1−1 src/Language/PureScript/Sugar/Names/Imports.hs+3−2
psci/PSCi.hs+1−1
@@ -242,7 +242,7 @@ createTemporaryModuleForImports PSCiState{psciImportedModules = imports} =
242242 P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName (importDecl `map` imports) Nothing
243243
244244importDecl :: ImportedModule -> P.Declaration
245−importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ
245+importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ False
246246
247247indexFile :: FilePath
248248indexFile = ".psci_modules" ++ pathSeparator : "index.js"
psci/Parser.hs+3−1
@@ -106,7 +106,9 @@ psciLet = Decls <$> (P.reserved "let" *> P.indented *> manyDecls)
106106-- | Imports must be handled separately from other declarations, so that
107107-- :show import works, for example.
108108psciImport :: P.TokenParser Command
109−psciImport = Import <$> P.parseImportDeclaration'
109+psciImport = do
110+ (mn, declType, asQ, _) <- P.parseImportDeclaration'
111+ return $ Import (mn, declType, asQ)
110112
111113-- | Any other declaration that we don't need a 'special case' parser for
112114-- (like let or import declarations).
src/Language/PureScript/AST/Declarations.hs+2−1
@@ -153,8 +153,9 @@ data Declaration
153153 | FixityDeclaration Fixity String
154154 -- |
155155 -- A module import (module name, qualified/unqualified/hiding, optional "qualified as" name)
156+ -- TODO: also a boolean specifying whether the old `qualified` syntax was used, so a warning can be raised in desugaring (remove for 0.9)
156157 --
157− | ImportDeclaration ModuleName ImportDeclarationType (Maybe ModuleName)
158+ | ImportDeclaration ModuleName ImportDeclarationType (Maybe ModuleName) Bool
158159 -- |
159160 -- A type class declaration (name, argument, implies, member declarations)
160161 --
src/Language/PureScript/CoreFn/Desugar.hs+1−1
@@ -219,7 +219,7 @@ findQualModules decls =
219219-- Desugars import declarations from AST to CoreFn representation.
220220--
221221importToCoreFn :: A.Declaration -> Maybe ModuleName
222−importToCoreFn (A.ImportDeclaration name _ _) = Just name
222+importToCoreFn (A.ImportDeclaration name _ _ _) = Just name
223223importToCoreFn (A.PositionedDeclaration _ _ d) = importToCoreFn d
224224importToCoreFn _ = Nothing
225225
src/Language/PureScript/Docs/ParseAndDesugar.hs+2−2
@@ -108,9 +108,9 @@ fileInfoToString (FromDep _ fn) = fn
108108addDefaultImport :: P.ModuleName -> P.Module -> P.Module
109109addDefaultImport toImport m@(P.Module ss coms mn decls exps) =
110110 if isExistingImport `any` decls || mn == toImport then m
111− else P.Module ss coms mn (P.ImportDeclaration toImport P.Implicit Nothing : decls) exps
111+ else P.Module ss coms mn (P.ImportDeclaration toImport P.Implicit Nothing False : decls) exps
112112 where
113− isExistingImport (P.ImportDeclaration mn' _ _) | mn' == toImport = True
113+ isExistingImport (P.ImportDeclaration mn' _ _ _) | mn' == toImport = True
114114 isExistingImport (P.PositionedDeclaration _ _ d) = isExistingImport d
115115 isExistingImport _ = False
116116
src/Language/PureScript/Errors.hs+6
@@ -141,6 +141,7 @@ data SimpleErrorMessage
141141 | UnusedExplicitImport ModuleName [String]
142142 | UnusedDctorImport ProperName
143143 | UnusedDctorExplicitImport ProperName [ProperName]
144+ | DeprecatedQualifiedSyntax ModuleName ModuleName
144145 deriving (Show)
145146
146147-- | Error message hints, providing more detailed information about failure.
@@ -275,6 +276,7 @@ errorCode em = case unwrapErrorMessage em of
275276 UnusedExplicitImport{} -> "UnusedExplicitImport"
276277 UnusedDctorImport{} -> "UnusedDctorImport"
277278 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
279+ DeprecatedQualifiedSyntax{} -> "DeprecatedQualifiedSyntax"
278280
279281
280282-- |
@@ -692,6 +694,10 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
692694 paras [ line $ "The import of type " ++ runProperName name ++ " includes the following unused data constructors:"
693695 , indent $ paras $ map (line .runProperName) names ]
694696
697+ renderSimpleErrorMessage (DeprecatedQualifiedSyntax name qualName) =
698+ paras [ line $ "The import of type " ++ runModuleName name ++ " as " ++ runModuleName qualName ++ " uses the deprecated 'import qualified' syntax."
699+ , line $ "This syntax form will be removed in PureScript 0.9." ]
700+
695701 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
696702 renderHint (ErrorUnifyingTypes t1 t2) detail =
697703 paras [ detail
src/Language/PureScript/Externs.hs+1−1
@@ -173,7 +173,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
173173 fixityDecl _ = Nothing
174174
175175 importDecl :: Declaration -> Maybe ExternsImport
176− importDecl (ImportDeclaration m mt qmn) = Just (ExternsImport m mt qmn)
176+ importDecl (ImportDeclaration m mt qmn _) = Just (ExternsImport m mt qmn)
177177 importDecl (PositionedDeclaration _ _ d) = importDecl d
178178 importDecl _ = Nothing
179179
src/Language/PureScript/Make.hs+2−2
@@ -270,9 +270,9 @@ make MakeActions{..} ms = do
270270addDefaultImport :: ModuleName -> Module -> Module
271271addDefaultImport toImport m@(Module ss coms mn decls exps) =
272272 if isExistingImport `any` decls || mn == toImport then m
273− else Module ss coms mn (ImportDeclaration toImport Implicit Nothing : decls) exps
273+ else Module ss coms mn (ImportDeclaration toImport Implicit Nothing False : decls) exps
274274 where
275− isExistingImport (ImportDeclaration mn' _ _) | mn' == toImport = True
275+ isExistingImport (ImportDeclaration mn' _ _ _) | mn' == toImport = True
276276 isExistingImport (PositionedDeclaration _ _ d) = isExistingImport d
277277 isExistingImport _ = False
278278
src/Language/PureScript/ModuleDependencies.hs+1−1
@@ -57,7 +57,7 @@ usedModules :: Declaration -> [ModuleName]
5757usedModules = let (f, _, _, _, _) = everythingOnValues (++) forDecls forValues (const []) (const []) (const []) in nub . f
5858 where
5959 forDecls :: Declaration -> [ModuleName]
60− forDecls (ImportDeclaration mn _ _) = [mn]
60+ forDecls (ImportDeclaration mn _ _ _) = [mn]
6161 forDecls _ = []
6262
6363 forValues :: Expr -> [ModuleName]
src/Language/PureScript/Parser/Declarations.hs+5−5
@@ -141,10 +141,10 @@ parseFixityDeclaration = do
141141
142142parseImportDeclaration :: TokenParser Declaration
143143parseImportDeclaration = do
144− (mn, declType, asQ) <- parseImportDeclaration'
145− return $ ImportDeclaration mn declType asQ
144+ (mn, declType, asQ, isOldSyntax) <- parseImportDeclaration'
145+ return $ ImportDeclaration mn declType asQ isOldSyntax
146146
147−parseImportDeclaration' :: TokenParser (ModuleName, ImportDeclarationType, Maybe ModuleName)
147+parseImportDeclaration' :: TokenParser (ModuleName, ImportDeclarationType, Maybe ModuleName, Bool)
148148parseImportDeclaration' = do
149149 reserved "import"
150150 indented
@@ -154,7 +154,7 @@ parseImportDeclaration' = do
154154 moduleName' <- moduleName
155155 declType <- reserved "hiding" *> qualifyingList Hiding <|> qualifyingList Explicit
156156 qName <- P.optionMaybe qualifiedName
157− return (moduleName', declType, qName)
157+ return (moduleName', declType, qName, False)
158158 qualifiedName = reserved "as" *> moduleName
159159 qualImport = do
160160 reserved "qualified"
@@ -162,7 +162,7 @@ parseImportDeclaration' = do
162162 moduleName' <- moduleName
163163 declType <- qualifyingList Explicit
164164 qName <- qualifiedName
165− return (moduleName', declType, Just qName)
165+ return (moduleName', declType, Just qName, True)
166166 qualifyingList expectedType = do
167167 idents <- P.optionMaybe $ indented *> parens (commaSep parseDeclarationRef)
168168 return $ fromMaybe Implicit (expectedType <$> idents)
src/Language/PureScript/Sugar/Names.hs+1−1
@@ -142,7 +142,7 @@ elaborateImports imps (Module ss coms mn decls exps) = Module ss coms mn decls'
142142 fqValues (Var (Qualified (Just mn') _)) | mn' `notElem` importedModules imps = [mn']
143143 fqValues _ = []
144144 mkImport :: ModuleName -> Declaration
145− mkImport mn' = ImportDeclaration mn' (Explicit []) Nothing
145+ mkImport mn' = ImportDeclaration mn' (Explicit []) Nothing False
146146
147147-- |
148148-- Replaces all local names with qualified names within a module and checks that all existing
src/Language/PureScript/Sugar/Names/Imports.hs+3−2
@@ -25,7 +25,7 @@ import Prelude ()
2525import Prelude.Compat
2626
2727import Data.List (find)
28−import Data.Maybe (fromMaybe, isNothing)
28+import Data.Maybe (fromMaybe, isNothing, fromJust)
2929import Data.Foldable (traverse_)
3030
3131import Control.Arrow (first)
@@ -48,7 +48,8 @@ import Language.PureScript.Sugar.Names.Env
4848findImports :: forall m. (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => [Declaration] -> m (M.Map ModuleName [(Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)])
4949findImports = foldM (go Nothing) M.empty
5050 where
51− go pos result (ImportDeclaration mn typ qual) = do
51+ go pos result (ImportDeclaration mn typ qual isOldSyntax) = do
52+ when isOldSyntax . tell . errorMessage $ DeprecatedQualifiedSyntax mn (fromJust qual)
5253 checkImportRefType typ
5354 let imp = (pos, typ, qual)
5455 return $ M.insert mn (maybe [imp] (imp :) (mn `M.lookup` result)) result