Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/failing/OverlappingReExport.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ module B where

module C (module A, module M2) where
import A
import qualified B as M2
import B as M2
2 changes: 1 addition & 1 deletion examples/passing/AutoPrelude2.purs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main where

import Prelude
import qualified Prelude as P
import Prelude as P
import Control.Monad.Eff.Console

f :: forall a. a -> a
Expand Down
2 changes: 1 addition & 1 deletion examples/passing/ModuleExportQualified.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module A (module Prelude) where

module Main where
import Control.Monad.Eff.Console
import qualified A as B
import A as B

main = do
print (B.show 1.0)
3 changes: 1 addition & 2 deletions examples/passing/OptionalQualified.purs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Main where

-- qualified import with the "qualified" keyword
import qualified Prelude as P
import Prelude as P

-- qualified import without the "qualified" keyword
import Control.Monad.Eff.Console as Console
Expand Down
2 changes: 1 addition & 1 deletion examples/passing/QualifiedQualifiedImports.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Main where

-- qualified import with qualified imported names
import qualified Control.Monad.Eff.Console (log) as Console
import Control.Monad.Eff.Console (log) as Console

main = Console.log "Success!"
2 changes: 1 addition & 1 deletion examples/passing/ReExportQualified.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module B where

module C (module A, module M2) where
import A
import qualified B as M2
import B as M2

module Main where

Expand Down
7 changes: 2 additions & 5 deletions psci/PSCi/Completion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Prelude.Compat

import Data.Maybe (mapMaybe)
import Data.List (nub, nubBy, sortBy, isPrefixOf, stripPrefix)
import Data.Char (isUpper)
import Data.Function (on)

import Control.Arrow (second)
Expand Down Expand Up @@ -87,10 +86,8 @@ directiveArg _ Kind = [CtxType]
completeImport :: [String] -> String -> [CompletionContext]
completeImport ws w' =
case (ws, w') of
(["import"], w) | headSatisfies isUpper w -> [CtxModule]
(["import"], _) -> [CtxModule, CtxFixed "qualified"]
(["import", "qualified"], _) -> [CtxModule]
_ -> []
(["import"], _) -> [CtxModule]
_ -> []

headSatisfies :: (a -> Bool) -> [a] -> Bool
headSatisfies p str =
Expand Down
2 changes: 1 addition & 1 deletion psci/PSCi/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ createTemporaryModuleForImports PSCiState{psciImportedModules = imports} =
P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName (importDecl `map` imports) Nothing

importDecl :: ImportedModule -> P.Declaration
importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ False
importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ

indexFile :: FilePath
indexFile = ".psci_modules" ++ pathSeparator : "index.js"
Expand Down
2 changes: 1 addition & 1 deletion psci/PSCi/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ psciLet = Decls <$> (P.reserved "let" *> P.indented *> manyDecls)
-- :show import works, for example.
psciImport :: P.TokenParser Command
psciImport = do
(mn, declType, asQ, _) <- P.parseImportDeclaration'
(mn, declType, asQ) <- P.parseImportDeclaration'
return $ Import (mn, declType, asQ)

-- | Any other declaration that we don't need a 'special case' parser for
Expand Down
7 changes: 3 additions & 4 deletions src/Language/PureScript/AST/Declarations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ getModuleName (Module _ _ name _ _) = name
addDefaultImport :: ModuleName -> Module -> Module
addDefaultImport toImport m@(Module ss coms mn decls exps) =
if isExistingImport `any` decls || mn == toImport then m
else Module ss coms mn (ImportDeclaration toImport Implicit Nothing False : decls) exps
else Module ss coms mn (ImportDeclaration toImport Implicit Nothing : decls) exps
where
isExistingImport (ImportDeclaration mn' _ _ _) | mn' == toImport = True
isExistingImport (ImportDeclaration mn' _ _) | mn' == toImport = True
isExistingImport (PositionedDeclaration _ _ d) = isExistingImport d
isExistingImport _ = False

Expand Down Expand Up @@ -198,9 +198,8 @@ data Declaration
| FixityDeclaration Fixity String (Maybe (Qualified FixityAlias))
-- |
-- A module import (module name, qualified/unqualified/hiding, optional "qualified as" name)
-- TODO: also a boolean specifying whether the old `qualified` syntax was used, so a warning can be raised in desugaring (remove for 0.9)
--
| ImportDeclaration ModuleName ImportDeclarationType (Maybe ModuleName) Bool
| ImportDeclaration ModuleName ImportDeclarationType (Maybe ModuleName)
-- |
-- A type class declaration (name, argument, implies, member declarations)
--
Expand Down
2 changes: 1 addition & 1 deletion src/Language/PureScript/CoreFn/Desugar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ findQualModules decls =
-- Desugars import declarations from AST to CoreFn representation.
--
importToCoreFn :: A.Declaration -> Maybe (Ann, ModuleName)
importToCoreFn (A.ImportDeclaration name _ _ _) = Just (nullAnn, name)
importToCoreFn (A.ImportDeclaration name _ _) = Just (nullAnn, name)
importToCoreFn (A.PositionedDeclaration ss _ d) =
((,) (Just ss, [], Nothing, Nothing) . snd) <$> importToCoreFn d
importToCoreFn _ = Nothing
Expand Down
11 changes: 0 additions & 11 deletions src/Language/PureScript/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ data SimpleErrorMessage
| UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
| DeprecatedOperatorDecl String
| DeprecatedOperatorSection Expr (Either Expr Expr)
| DeprecatedQualifiedSyntax ModuleName ModuleName
| DeprecatedClassImport ModuleName (ProperName 'ClassName)
| DeprecatedClassExport (ProperName 'ClassName)
| DuplicateSelectiveImport ModuleName
Expand Down Expand Up @@ -331,7 +330,6 @@ errorCode em = case unwrapErrorMessage em of
UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
DeprecatedOperatorDecl{} -> "DeprecatedOperatorDecl"
DeprecatedOperatorSection{} -> "DeprecatedOperatorSection"
DeprecatedQualifiedSyntax{} -> "DeprecatedQualifiedSyntax"
DeprecatedClassImport{} -> "DeprecatedClassImport"
DeprecatedClassExport{} -> "DeprecatedClassExport"
DuplicateSelectiveImport{} -> "DuplicateSelectiveImport"
Expand Down Expand Up @@ -463,8 +461,6 @@ errorSuggestion err = case err of
UnusedImport{} -> emptySuggestion
RedundantEmptyHidingImport{} -> emptySuggestion
DuplicateImport{} -> emptySuggestion
DeprecatedQualifiedSyntax name qualName -> suggest $
"import " ++ runModuleName name ++ " as " ++ runModuleName qualName
UnusedExplicitImport mn _ qual refs -> suggest $ importSuggestion mn refs qual
ImplicitImport mn refs -> suggest $ importSuggestion mn refs Nothing
ImplicitQualifiedImport mn asModule refs -> suggest $ importSuggestion mn refs (Just asModule)
Expand Down Expand Up @@ -951,13 +947,6 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
renderOperator (PositionedValue _ _ ex) = renderOperator ex
renderOperator (Var (Qualified _ (Op ident))) = line ident
renderOperator other = Box.hcat Box.top [ line "`", prettyPrintValue valueDepth other, line "`" ]
renderSimpleErrorMessage (DeprecatedQualifiedSyntax name qualName) =
paras [ line "Import uses the deprecated 'qualified' syntax:"
, indent $ line $ "import qualified " ++ runModuleName name ++ " as " ++ runModuleName qualName
, line "Should instead use the form:"
, indent $ line $ "import " ++ runModuleName name ++ " as " ++ runModuleName qualName
, line "The deprecated syntax will be removed in PureScript 0.9."
]

renderSimpleErrorMessage (DeprecatedClassImport mn name) =
paras [ line $ "Class import from " ++ runModuleName mn ++ " uses deprecated syntax that omits the 'class' keyword:"
Expand Down
2 changes: 1 addition & 1 deletion src/Language/PureScript/Externs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
fixityDecl _ = Nothing

importDecl :: Declaration -> Maybe ExternsImport
importDecl (ImportDeclaration m mt qmn _) = Just (ExternsImport m mt qmn)
importDecl (ImportDeclaration m mt qmn) = Just (ExternsImport m mt qmn)
importDecl (PositionedDeclaration _ _ d) = importDecl d
importDecl _ = Nothing

Expand Down
9 changes: 4 additions & 5 deletions src/Language/PureScript/Ide/Imports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ parseImportsWithModuleName ls = do
(P.Module _ _ mn decls _) <- moduleParse ls
pure (mn, concatMap mkImport (unwrapPositioned <$> decls))
where
mkImport (P.ImportDeclaration mn (P.Explicit refs) qual _) =
mkImport (P.ImportDeclaration mn (P.Explicit refs) qual) =
[Import mn (P.Explicit (unwrapPositionedRef <$> refs)) qual]
mkImport (P.ImportDeclaration mn it qual _) = [Import mn it qual]
mkImport (P.ImportDeclaration mn it qual) = [Import mn it qual]
mkImport _ = []

sliceImportSection :: [Text] -> Either String (P.ModuleName, [Text], [Import], [Text])
Expand Down Expand Up @@ -348,8 +348,7 @@ parseImport :: Text -> Maybe Import
parseImport t =
case P.lex "<psc-ide>" (T.unpack t)
>>= P.runTokenParser "<psc-ide>" P.parseImportDeclaration' of
Right (mn, P.Explicit refs, mmn, _) ->
Right (mn, P.Explicit refs, mmn) ->
Just (Import mn (P.Explicit (unwrapPositionedRef <$> refs)) mmn)
Right (mn, idt, mmn, _) -> Just (Import mn idt mmn)
Right (mn, idt, mmn) -> Just (Import mn idt mmn)
Left _ -> Nothing

2 changes: 1 addition & 1 deletion src/Language/PureScript/Ide/Rebuild.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ sortExterns m ex = do
mkShallowModule P.ExternsFile{..} =
P.Module undefined [] efModuleName (map mkImport efImports) Nothing
mkImport (P.ExternsImport mn it iq) =
P.ImportDeclaration mn it iq False
P.ImportDeclaration mn it iq
getExtern mn = M.lookup mn ex
-- Sort a list so its elements appear in the same order as in another list.
inOrderOf :: (Ord a) => [a] -> [a] -> [a]
Expand Down
6 changes: 3 additions & 3 deletions src/Language/PureScript/Ide/SourceFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ getImportsForFile fp = do
let imports = getImports module'
pure (mkModuleImport . unwrapPositionedImport <$> imports)
where
mkModuleImport (D.ImportDeclaration mn importType' qualifier _) =
mkModuleImport (D.ImportDeclaration mn importType' qualifier) =
ModuleImport
(T.pack (N.runModuleName mn))
importType'
(T.pack . N.runModuleName <$> qualifier)
mkModuleImport _ = error "Shouldn't have gotten anything but Imports here"
unwrapPositionedImport (D.ImportDeclaration mn importType' qualifier b) =
D.ImportDeclaration mn (unwrapImportType importType') qualifier b
unwrapPositionedImport (D.ImportDeclaration mn importType' qualifier) =
D.ImportDeclaration mn (unwrapImportType importType') qualifier
unwrapPositionedImport x = x
unwrapImportType (D.Explicit decls) = D.Explicit (map unwrapPositionedRef decls)
unwrapImportType (D.Hiding decls) = D.Hiding (map unwrapPositionedRef decls)
Expand Down
4 changes: 2 additions & 2 deletions src/Language/PureScript/Linter/Imports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ lintImports (Module _ _ mn mdecls mexports) env usedImps = do
where

countOpenImports :: Declaration -> Int
countOpenImports (ImportDeclaration mn' Implicit Nothing _) | not (isPrim mn') = 1
countOpenImports (ImportDeclaration mn' (Hiding _) Nothing _) | not (isPrim mn') = 1
countOpenImports (ImportDeclaration mn' Implicit Nothing) | not (isPrim mn') = 1
countOpenImports (ImportDeclaration mn' (Hiding _) Nothing) | not (isPrim mn') = 1
countOpenImports (PositionedDeclaration _ _ d) = countOpenImports d
countOpenImports _ = 0

Expand Down
4 changes: 2 additions & 2 deletions src/Language/PureScript/ModuleDependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ sortModules ms = do
-- Extract module names that have been brought into scope by an `as` import.
extractQualAs :: Declaration -> [ModuleName]
extractQualAs (PositionedDeclaration _ _ d) = extractQualAs d
extractQualAs (ImportDeclaration _ _ (Just am) _) = [am]
extractQualAs (ImportDeclaration _ _ (Just am)) = [am]
extractQualAs _ = []

-- |
Expand All @@ -65,7 +65,7 @@ usedModules ams d =
where

forDecls :: Declaration -> [ModuleName]
forDecls (ImportDeclaration mn _ _ _) =
forDecls (ImportDeclaration mn _ _) =
-- Regardless of whether an imported module is qualified we still need to
-- take into account its import to build an accurate list of dependencies.
[mn]
Expand Down
23 changes: 7 additions & 16 deletions src/Language/PureScript/Parser/Declarations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,19 @@ parseFixityDeclaration = do

parseImportDeclaration :: TokenParser Declaration
parseImportDeclaration = do
(mn, declType, asQ, isOldSyntax) <- parseImportDeclaration'
return $ ImportDeclaration mn declType asQ isOldSyntax
(mn, declType, asQ) <- parseImportDeclaration'
return $ ImportDeclaration mn declType asQ

parseImportDeclaration' :: TokenParser (ModuleName, ImportDeclarationType, Maybe ModuleName, Bool)
parseImportDeclaration' :: TokenParser (ModuleName, ImportDeclarationType, Maybe ModuleName)
parseImportDeclaration' = do
reserved "import"
indented
qualImport <|> stdImport
moduleName' <- moduleName
declType <- reserved "hiding" *> qualifyingList Hiding <|> qualifyingList Explicit
qName <- P.optionMaybe qualifiedName
return (moduleName', declType, qName)
where
stdImport = do
moduleName' <- moduleName
declType <- reserved "hiding" *> qualifyingList Hiding <|> qualifyingList Explicit
qName <- P.optionMaybe qualifiedName
return (moduleName', declType, qName, False)
qualifiedName = reserved "as" *> moduleName
qualImport = do
reserved "qualified"
indented
moduleName' <- moduleName
declType <- qualifyingList Explicit
qName <- qualifiedName
return (moduleName', declType, Just qName, True)
qualifyingList expectedType = do
declType <- P.optionMaybe (expectedType <$> (indented *> parens (commaSep parseDeclarationRef)))
return $ fromMaybe Implicit declType
Expand Down
9 changes: 4 additions & 5 deletions src/Language/PureScript/Sugar/Names/Imports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Prelude.Compat
import Data.Foldable (traverse_, for_)
import Data.Function (on)
import Data.List (find, sortBy, groupBy, (\\))
import Data.Maybe (fromMaybe, isNothing, fromJust)
import Data.Maybe (fromMaybe, isNothing)
import Data.Traversable (for)

import Control.Arrow (first)
Expand Down Expand Up @@ -43,8 +43,7 @@ findImports
-> m (M.Map ModuleName [(Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)])
findImports = foldM (go Nothing) M.empty
where
go pos result (ImportDeclaration mn typ qual isOldSyntax) = do
when isOldSyntax . tell . errorMessage $ DeprecatedQualifiedSyntax mn (fromJust qual)
go pos result (ImportDeclaration mn typ qual) = do
let imp = (pos, typ, qual)
return $ M.insert mn (maybe [imp] (imp :) (mn `M.lookup` result)) result
go _ result (PositionedDeclaration pos _ d) = warnAndRethrowWithPosition pos $ go (Just pos) result d
Expand Down Expand Up @@ -137,13 +136,13 @@ resolveImports env (Module ss coms currentModule decls exps) =
updateImportRef :: Declaration -> m Declaration
updateImportRef (PositionedDeclaration pos com d) =
warnAndRethrowWithPosition pos $ PositionedDeclaration pos com <$> updateImportRef d
updateImportRef (ImportDeclaration mn typ qual isOldSyntax) = do
updateImportRef (ImportDeclaration mn typ qual) = do
modExports <- getExports env mn
typ' <- case typ of
Implicit -> return Implicit
Explicit refs -> Explicit <$> updateProperRef mn modExports `traverse` refs
Hiding refs -> Hiding <$> updateProperRef mn modExports `traverse` refs
return $ ImportDeclaration mn typ' qual isOldSyntax
return $ ImportDeclaration mn typ' qual
updateImportRef other = return other

updateProperRef :: ModuleName -> Exports -> DeclarationRef -> m DeclarationRef
Expand Down
4 changes: 1 addition & 3 deletions tests/TestPsci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ completionTestData =
-- import should complete module names
, ("import Control.Monad.E", map ("import Control.Monad.Eff" ++) ["", ".Unsafe", ".Class", ".Console"])
, ("import Control.Monad.Eff.", map ("import Control.Monad.Eff" ++) [".Unsafe", ".Class", ".Console"])
, ("import qualified Control.Monad.Eff.", map ("import qualified Control.Monad.Eff" ++) [".Unsafe", ".Class", ".Console"])

-- :load, :module should complete file paths
, (":l tests/support/psci/", [":l tests/support/psci/Sample.purs"])
Expand Down Expand Up @@ -91,8 +90,7 @@ completionTestData =

-- a few other import tests
, ("impor", ["import"])
, ("import q", ["import qualified"])
, ("import ", map ("import " ++) supportModules ++ ["import qualified"])
, ("import ", map ("import " ++) supportModules)
, ("import Prelude ", [])

-- String and number literals should not be completed
Expand Down