From 2f221d772e7323f35c372059d71e6b6135cc23c0 Mon Sep 17 00:00:00 2001 From: Isaac Elliott Date: Tue, 4 Jul 2017 17:36:00 +1000 Subject: [PATCH 1/4] Fix and regression tests for #2197 --- examples/failing/2197-shouldFail.purs | 10 ++++++++++ examples/passing/2197.purs | 11 +++++++++++ src/Language/PureScript/AST/Declarations.hs | 13 ++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 examples/failing/2197-shouldFail.purs create mode 100644 examples/passing/2197.purs diff --git a/examples/failing/2197-shouldFail.purs b/examples/failing/2197-shouldFail.purs new file mode 100644 index 0000000000..a211f195d0 --- /dev/null +++ b/examples/failing/2197-shouldFail.purs @@ -0,0 +1,10 @@ +-- @shouldFailWith ScopeConflict +module Main where + +import Prim as P +import Prim (Number) + +type Number = P.Number + +z :: Number +z = 0.0 diff --git a/examples/passing/2197.purs b/examples/passing/2197.purs new file mode 100644 index 0000000000..8d99875073 --- /dev/null +++ b/examples/passing/2197.purs @@ -0,0 +1,11 @@ +module Main where + +import Control.Monad.Eff.Console +import Prim as P + +type Number = P.Number + +z :: Number +z = 0.0 + +main = log "Done" diff --git a/src/Language/PureScript/AST/Declarations.hs b/src/Language/PureScript/AST/Declarations.hs index d897ee0a7c..a4ea2fdd78 100644 --- a/src/Language/PureScript/AST/Declarations.hs +++ b/src/Language/PureScript/AST/Declarations.hs @@ -229,12 +229,19 @@ getModuleSourceSpan (Module ss _ _ _ _) = ss -- | -- Add an import declaration for a module if it does not already explicitly import it. -- +-- Will not import an unqualified module if that module has already been imported qualified. +-- (See #2197) +-- addDefaultImport :: Qualified ModuleName -> Module -> Module addDefaultImport (Qualified toImportAs toImport) m@(Module ss coms mn decls exps) = if isExistingImport `any` decls || mn == toImport then m else Module ss coms mn (ImportDeclaration (ss, []) toImport Implicit toImportAs : decls) exps where - isExistingImport (ImportDeclaration _ mn' _ as') | mn' == toImport && as' == toImportAs = True + isExistingImport (ImportDeclaration _ mn' _ as') + | mn' == toImport = + case toImportAs of + Nothing -> True + _ -> as' == toImportAs isExistingImport _ = False -- | Adds import declarations to a module for an implicit Prim import and Prim @@ -244,8 +251,8 @@ importPrim = let primModName = ModuleName [ProperName C.prim] in - addDefaultImport (Qualified Nothing primModName) - . addDefaultImport (Qualified (Just primModName) primModName) + addDefaultImport (Qualified (Just primModName) primModName) + . addDefaultImport (Qualified Nothing primModName) -- | -- An item in a list of explicit imports or exports From 489cd5d55067a79abb0054ab7cb73684079f5239 Mon Sep 17 00:00:00 2001 From: Isaac Elliott Date: Tue, 4 Jul 2017 17:48:34 +1000 Subject: [PATCH 2/4] Updated Prim module documentation --- src/Language/PureScript/Docs/Prim.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Language/PureScript/Docs/Prim.hs b/src/Language/PureScript/Docs/Prim.hs index 2a5e62c641..aa8b68c3e4 100644 --- a/src/Language/PureScript/Docs/Prim.hs +++ b/src/Language/PureScript/Docs/Prim.hs @@ -12,7 +12,7 @@ import qualified Language.PureScript as P primDocsModule :: Module primDocsModule = Module { modName = P.moduleNameFromString "Prim" - , modComments = Just "The Prim module is embedded in the PureScript compiler in order to provide compiler support for certain types — for example, value literals, or syntax sugar." + , modComments = Just "The Prim module is embedded in the PureScript compiler in order to provide compiler support for certain types — for example, value literals, or syntax sugar. It is implicitly imported unqualified in every module except those that list it as a qualified import." , modDeclarations = [ function , array From 233dc4ff7169130e5081a77243dd42553cd2fa6f Mon Sep 17 00:00:00 2001 From: Isaac Elliott Date: Wed, 5 Jul 2017 08:44:27 +1000 Subject: [PATCH 3/4] Added test using Record type --- examples/passing/2197.purs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/passing/2197.purs b/examples/passing/2197.purs index 8d99875073..a0c808f350 100644 --- a/examples/passing/2197.purs +++ b/examples/passing/2197.purs @@ -4,6 +4,7 @@ import Control.Monad.Eff.Console import Prim as P type Number = P.Number +type Test = {} z :: Number z = 0.0 From 809bb7574b068cab37d7279adcb9c4e5e337b982 Mon Sep 17 00:00:00 2001 From: Isaac Elliott Date: Wed, 5 Jul 2017 09:06:29 +1000 Subject: [PATCH 4/4] Added some peace-of-mind tests --- examples/failing/2197-shouldFail2.purs | 7 +++++++ examples/passing/{2197.purs => 2197-1.purs} | 0 examples/passing/2197-2.purs | 11 +++++++++++ 3 files changed, 18 insertions(+) create mode 100644 examples/failing/2197-shouldFail2.purs rename examples/passing/{2197.purs => 2197-1.purs} (100%) create mode 100644 examples/passing/2197-2.purs diff --git a/examples/failing/2197-shouldFail2.purs b/examples/failing/2197-shouldFail2.purs new file mode 100644 index 0000000000..fb1b11b5d7 --- /dev/null +++ b/examples/failing/2197-shouldFail2.purs @@ -0,0 +1,7 @@ +-- @shouldFailWith UnknownName +module Main where + +import Prim (Boolean) + +z :: Number +z = 0.0 diff --git a/examples/passing/2197.purs b/examples/passing/2197-1.purs similarity index 100% rename from examples/passing/2197.purs rename to examples/passing/2197-1.purs diff --git a/examples/passing/2197-2.purs b/examples/passing/2197-2.purs new file mode 100644 index 0000000000..94354e94cd --- /dev/null +++ b/examples/passing/2197-2.purs @@ -0,0 +1,11 @@ +module Main where + +import Control.Monad.Eff.Console +import Prim (Int) + +type Number = Int + +z :: Number +z = 0 + +main = log "Done"