Skip to content

Commit 42702e8

Browse files
committed
Add deprecation warning for import qualified syntax
1 parent 17eaed5 commit 42702e8

File tree

12 files changed

+28
-18
lines changed

12 files changed

+28
-18
lines changed

psci/PSCi.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ createTemporaryModuleForImports PSCiState{psciImportedModules = imports} =
242242
P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName (importDecl `map` imports) Nothing
243243

244244
importDecl :: 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

247247
indexFile :: FilePath
248248
indexFile = ".psci_modules" ++ pathSeparator : "index.js"

psci/Parser.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
108108
psciImport :: 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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ findQualModules decls =
219219
-- Desugars import declarations from AST to CoreFn representation.
220220
--
221221
importToCoreFn :: A.Declaration -> Maybe ModuleName
222-
importToCoreFn (A.ImportDeclaration name _ _) = Just name
222+
importToCoreFn (A.ImportDeclaration name _ _ _) = Just name
223223
importToCoreFn (A.PositionedDeclaration _ _ d) = importToCoreFn d
224224
importToCoreFn _ = Nothing
225225

src/Language/PureScript/Docs/ParseAndDesugar.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ fileInfoToString (FromDep _ fn) = fn
108108
addDefaultImport :: P.ModuleName -> P.Module -> P.Module
109109
addDefaultImport 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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ make MakeActions{..} ms = do
270270
addDefaultImport :: ModuleName -> Module -> Module
271271
addDefaultImport 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ usedModules :: Declaration -> [ModuleName]
5757
usedModules = 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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ parseFixityDeclaration = do
141141

142142
parseImportDeclaration :: TokenParser Declaration
143143
parseImportDeclaration = 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)
148148
parseImportDeclaration' = do
149149
reserved "import"
150150
indented
@@ -154,15 +154,15 @@ 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"
161161
indented
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)

0 commit comments

Comments
 (0)