git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add deprecation warning for import qualified syntax
42702e8Gary Burgess
psci/PSCi.hs+1−1
@@ -242,7 +242,7 @@ createTemporaryModuleForImports PSCiState{psciImportedModules = imports} =
242 P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName (importDecl `map` imports) Nothing
242 P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName (importDecl `map` imports) Nothing
243
243
244importDecl :: ImportedModule -> P.Declaration
244importDecl :: ImportedModule -> P.Declaration
245−importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ
245+importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ False
246
246
247indexFile :: FilePath
247indexFile :: FilePath
248indexFile = ".psci_modules" ++ pathSeparator : "index.js"
248indexFile = ".psci_modules" ++ pathSeparator : "index.js"
psci/Parser.hs+3−1
@@ -106,7 +106,9 @@ psciLet = Decls <$> (P.reserved "let" *> P.indented *> manyDecls)
106-- | Imports must be handled separately from other declarations, so that
106-- | Imports must be handled separately from other declarations, so that
107-- :show import works, for example.
107-- :show import works, for example.
108psciImport :: P.TokenParser Command
108psciImport :: P.TokenParser Command
109+psciImport = do
109−psciImport = Import <$> P.parseImportDeclaration'
110+ (mn, declType, asQ, _) <- P.parseImportDeclaration'
111+ return $ Import (mn, declType, asQ)
110
112
111-- | Any other declaration that we don't need a 'special case' parser for
113-- | Any other declaration that we don't need a 'special case' parser for
112-- (like let or import declarations).
114-- (like let or import declarations).
src/Language/PureScript/AST/Declarations.hs+2−1
@@ -153,8 +153,9 @@ data Declaration
153 | FixityDeclaration Fixity String
153 | FixityDeclaration Fixity String
154 -- |
154 -- |
155 -- A module import (module name, qualified/unqualified/hiding, optional "qualified as" name)
155 -- 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)
156 --
157 --
157− | ImportDeclaration ModuleName ImportDeclarationType (Maybe ModuleName)
158+ | ImportDeclaration ModuleName ImportDeclarationType (Maybe ModuleName) Bool
158 -- |
159 -- |
159 -- A type class declaration (name, argument, implies, member declarations)
160 -- A type class declaration (name, argument, implies, member declarations)
160 --
161 --
src/Language/PureScript/CoreFn/Desugar.hs+1−1
@@ -219,7 +219,7 @@ findQualModules decls =
219-- Desugars import declarations from AST to CoreFn representation.
219-- Desugars import declarations from AST to CoreFn representation.
220--
220--
221importToCoreFn :: A.Declaration -> Maybe ModuleName
221importToCoreFn :: A.Declaration -> Maybe ModuleName
222−importToCoreFn (A.ImportDeclaration name _ _) = Just name
222+importToCoreFn (A.ImportDeclaration name _ _ _) = Just name
223importToCoreFn (A.PositionedDeclaration _ _ d) = importToCoreFn d
223importToCoreFn (A.PositionedDeclaration _ _ d) = importToCoreFn d
224importToCoreFn _ = Nothing
224importToCoreFn _ = Nothing
225
225
src/Language/PureScript/Docs/ParseAndDesugar.hs+2−2
@@ -108,9 +108,9 @@ fileInfoToString (FromDep _ fn) = fn
108addDefaultImport :: P.ModuleName -> P.Module -> P.Module
108addDefaultImport :: P.ModuleName -> P.Module -> P.Module
109addDefaultImport toImport m@(P.Module ss coms mn decls exps) =
109addDefaultImport toImport m@(P.Module ss coms mn decls exps) =
110 if isExistingImport `any` decls || mn == toImport then m
110 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
112 where
112 where
113− isExistingImport (P.ImportDeclaration mn' _ _) | mn' == toImport = True
113+ isExistingImport (P.ImportDeclaration mn' _ _ _) | mn' == toImport = True
114 isExistingImport (P.PositionedDeclaration _ _ d) = isExistingImport d
114 isExistingImport (P.PositionedDeclaration _ _ d) = isExistingImport d
115 isExistingImport _ = False
115 isExistingImport _ = False
116
116
src/Language/PureScript/Errors.hs+6
@@ -141,6 +141,7 @@ data SimpleErrorMessage
141 | UnusedExplicitImport ModuleName [String]
141 | UnusedExplicitImport ModuleName [String]
142 | UnusedDctorImport ProperName
142 | UnusedDctorImport ProperName
143 | UnusedDctorExplicitImport ProperName [ProperName]
143 | UnusedDctorExplicitImport ProperName [ProperName]
144+ | DeprecatedQualifiedSyntax ModuleName ModuleName
144 deriving (Show)
145 deriving (Show)
145
146
146-- | Error message hints, providing more detailed information about failure.
147-- | Error message hints, providing more detailed information about failure.
@@ -275,6 +276,7 @@ errorCode em = case unwrapErrorMessage em of
275 UnusedExplicitImport{} -> "UnusedExplicitImport"
276 UnusedExplicitImport{} -> "UnusedExplicitImport"
276 UnusedDctorImport{} -> "UnusedDctorImport"
277 UnusedDctorImport{} -> "UnusedDctorImport"
277 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
278 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
279+ DeprecatedQualifiedSyntax{} -> "DeprecatedQualifiedSyntax"
278
280
279
281
280-- |
282-- |
@@ -692,6 +694,10 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
692 paras [ line $ "The import of type " ++ runProperName name ++ " includes the following unused data constructors:"
694 paras [ line $ "The import of type " ++ runProperName name ++ " includes the following unused data constructors:"
693 , indent $ paras $ map (line .runProperName) names ]
695 , indent $ paras $ map (line .runProperName) names ]
694
696
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+
695 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
701 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
696 renderHint (ErrorUnifyingTypes t1 t2) detail =
702 renderHint (ErrorUnifyingTypes t1 t2) detail =
697 paras [ detail
703 paras [ detail
src/Language/PureScript/Externs.hs+1−1
@@ -173,7 +173,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
173 fixityDecl _ = Nothing
173 fixityDecl _ = Nothing
174
174
175 importDecl :: Declaration -> Maybe ExternsImport
175 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)
177 importDecl (PositionedDeclaration _ _ d) = importDecl d
177 importDecl (PositionedDeclaration _ _ d) = importDecl d
178 importDecl _ = Nothing
178 importDecl _ = Nothing
179
179
src/Language/PureScript/Make.hs+2−2
@@ -270,9 +270,9 @@ make MakeActions{..} ms = do
270addDefaultImport :: ModuleName -> Module -> Module
270addDefaultImport :: ModuleName -> Module -> Module
271addDefaultImport toImport m@(Module ss coms mn decls exps) =
271addDefaultImport toImport m@(Module ss coms mn decls exps) =
272 if isExistingImport `any` decls || mn == toImport then m
272 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
274 where
274 where
275− isExistingImport (ImportDeclaration mn' _ _) | mn' == toImport = True
275+ isExistingImport (ImportDeclaration mn' _ _ _) | mn' == toImport = True
276 isExistingImport (PositionedDeclaration _ _ d) = isExistingImport d
276 isExistingImport (PositionedDeclaration _ _ d) = isExistingImport d
277 isExistingImport _ = False
277 isExistingImport _ = False
278
278
src/Language/PureScript/ModuleDependencies.hs+1−1
@@ -57,7 +57,7 @@ usedModules :: Declaration -> [ModuleName]
57usedModules = let (f, _, _, _, _) = everythingOnValues (++) forDecls forValues (const []) (const []) (const []) in nub . f
57usedModules = let (f, _, _, _, _) = everythingOnValues (++) forDecls forValues (const []) (const []) (const []) in nub . f
58 where
58 where
59 forDecls :: Declaration -> [ModuleName]
59 forDecls :: Declaration -> [ModuleName]
60− forDecls (ImportDeclaration mn _ _) = [mn]
60+ forDecls (ImportDeclaration mn _ _ _) = [mn]
61 forDecls _ = []
61 forDecls _ = []
62
62
63 forValues :: Expr -> [ModuleName]
63 forValues :: Expr -> [ModuleName]
src/Language/PureScript/Parser/Declarations.hs+5−5
@@ -141,10 +141,10 @@ parseFixityDeclaration = do
141
141
142parseImportDeclaration :: TokenParser Declaration
142parseImportDeclaration :: TokenParser Declaration
143parseImportDeclaration = do
143parseImportDeclaration = do
144− (mn, declType, asQ) <- parseImportDeclaration'
144+ (mn, declType, asQ, isOldSyntax) <- parseImportDeclaration'
145− return $ ImportDeclaration mn declType asQ
145+ return $ ImportDeclaration mn declType asQ isOldSyntax
146
146
147−parseImportDeclaration' :: TokenParser (ModuleName, ImportDeclarationType, Maybe ModuleName)
147+parseImportDeclaration' :: TokenParser (ModuleName, ImportDeclarationType, Maybe ModuleName, Bool)
148parseImportDeclaration' = do
148parseImportDeclaration' = do
149 reserved "import"
149 reserved "import"
150 indented
150 indented
@@ -154,7 +154,7 @@ parseImportDeclaration' = do
154 moduleName' <- moduleName
154 moduleName' <- moduleName
155 declType <- reserved "hiding" *> qualifyingList Hiding <|> qualifyingList Explicit
155 declType <- reserved "hiding" *> qualifyingList Hiding <|> qualifyingList Explicit
156 qName <- P.optionMaybe qualifiedName
156 qName <- P.optionMaybe qualifiedName
157− return (moduleName', declType, qName)
157+ return (moduleName', declType, qName, False)
158 qualifiedName = reserved "as" *> moduleName
158 qualifiedName = reserved "as" *> moduleName
159 qualImport = do
159 qualImport = do
160 reserved "qualified"
160 reserved "qualified"
@@ -162,7 +162,7 @@ parseImportDeclaration' = do
162 moduleName' <- moduleName
162 moduleName' <- moduleName
163 declType <- qualifyingList Explicit
163 declType <- qualifyingList Explicit
164 qName <- qualifiedName
164 qName <- qualifiedName
165− return (moduleName', declType, Just qName)
165+ return (moduleName', declType, Just qName, True)
166 qualifyingList expectedType = do
166 qualifyingList expectedType = do
167 idents <- P.optionMaybe $ indented *> parens (commaSep parseDeclarationRef)
167 idents <- P.optionMaybe $ indented *> parens (commaSep parseDeclarationRef)
168 return $ fromMaybe Implicit (expectedType <$> idents)
168 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'
142 fqValues (Var (Qualified (Just mn') _)) | mn' `notElem` importedModules imps = [mn']
142 fqValues (Var (Qualified (Just mn') _)) | mn' `notElem` importedModules imps = [mn']
143 fqValues _ = []
143 fqValues _ = []
144 mkImport :: ModuleName -> Declaration
144 mkImport :: ModuleName -> Declaration
145− mkImport mn' = ImportDeclaration mn' (Explicit []) Nothing
145+ mkImport mn' = ImportDeclaration mn' (Explicit []) Nothing False
146
146
147-- |
147-- |
148-- Replaces all local names with qualified names within a module and checks that all existing
148-- 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 ()
25import Prelude.Compat
25import Prelude.Compat
26
26
27import Data.List (find)
27import Data.List (find)
28−import Data.Maybe (fromMaybe, isNothing)
28+import Data.Maybe (fromMaybe, isNothing, fromJust)
29import Data.Foldable (traverse_)
29import Data.Foldable (traverse_)
30
30
31import Control.Arrow (first)
31import Control.Arrow (first)
@@ -48,7 +48,8 @@ import Language.PureScript.Sugar.Names.Env
48findImports :: forall m. (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => [Declaration] -> m (M.Map ModuleName [(Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)])
48findImports :: forall m. (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => [Declaration] -> m (M.Map ModuleName [(Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)])
49findImports = foldM (go Nothing) M.empty
49findImports = foldM (go Nothing) M.empty
50 where
50 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)
52 checkImportRefType typ
53 checkImportRefType typ
53 let imp = (pos, typ, qual)
54 let imp = (pos, typ, qual)
54 return $ M.insert mn (maybe [imp] (imp :) (mn `M.lookup` result)) result
55 return $ M.insert mn (maybe [imp] (imp :) (mn `M.lookup` result)) result