summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilFreeman <>2014-01-31 00:03:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2014-01-31 00:03:00 (GMT)
commit24dfd3a89162f778bbcf17c508f4beedd92881c2 (patch)
treebcfc2f1469c787d160ce3a08d0a137739c31f4aa
parentcbda56a6cf2d2900e13cc163ea248f836182b825 (diff)
version 0.3.6.10.3.6.1
-rw-r--r--purescript.cabal2
-rw-r--r--src/Language/PureScript/CodeGen/JS.hs6
-rw-r--r--src/Language/PureScript/TypeChecker/Monad.hs9
3 files changed, 13 insertions, 4 deletions
diff --git a/purescript.cabal b/purescript.cabal
index 95dad06..0f7e11a 100644
--- a/purescript.cabal
+++ b/purescript.cabal
@@ -1,5 +1,5 @@
name: purescript
-version: 0.3.6
+version: 0.3.6.1
cabal-version: >=1.8
build-type: Simple
license: MIT
diff --git a/src/Language/PureScript/CodeGen/JS.hs b/src/Language/PureScript/CodeGen/JS.hs
index d656e70..65a25e2 100644
--- a/src/Language/PureScript/CodeGen/JS.hs
+++ b/src/Language/PureScript/CodeGen/JS.hs
@@ -41,7 +41,7 @@ import Language.PureScript.Options
import Language.PureScript.CodeGen.JS.AST as AST
import Language.PureScript.Types
import Language.PureScript.CodeGen.Optimize
-import Language.PureScript.TypeChecker.Monad (canonicalizeType)
+import Language.PureScript.TypeChecker.Monad (canonicalizeDataConstructor)
-- |
-- Generate code in the simplified Javascript intermediate representation for all declarations in a module
@@ -199,7 +199,7 @@ binderToJs m e varName done (NullaryBinder ctor) =
then
return done
else
- return [JSIfElse (JSBinary EqualTo (JSAccessor "ctor" (JSVar varName)) (JSStringLiteral (show ((\(mp, nm) -> Qualified (Just mp) nm) $ canonicalizeType m e ctor)))) (JSBlock done) Nothing]
+ return [JSIfElse (JSBinary EqualTo (JSAccessor "ctor" (JSVar varName)) (JSStringLiteral (show ((\(mp, nm) -> Qualified (Just mp) nm) $ canonicalizeDataConstructor m e ctor)))) (JSBlock done) Nothing]
binderToJs m e varName done (UnaryBinder ctor b) = do
value <- fresh
js <- binderToJs m e value done b
@@ -208,7 +208,7 @@ binderToJs m e varName done (UnaryBinder ctor b) = do
then
return [success]
else
- return [JSIfElse (JSBinary EqualTo (JSAccessor "ctor" (JSVar varName)) (JSStringLiteral (show ((\(mp, nm) -> Qualified (Just mp) nm) $ canonicalizeType m e ctor))))
+ return [JSIfElse (JSBinary EqualTo (JSAccessor "ctor" (JSVar varName)) (JSStringLiteral (show ((\(mp, nm) -> Qualified (Just mp) nm) $ canonicalizeDataConstructor m e ctor))))
success
Nothing]
binderToJs m e varName done (ObjectBinder bs) = go done bs
diff --git a/src/Language/PureScript/TypeChecker/Monad.hs b/src/Language/PureScript/TypeChecker/Monad.hs
index 2eded09..392e876 100644
--- a/src/Language/PureScript/TypeChecker/Monad.hs
+++ b/src/Language/PureScript/TypeChecker/Monad.hs
@@ -210,6 +210,15 @@ canonicalizeType _ _ (Qualified (Just mn) nm) = (mn, nm)
canonicalizeType mn env (Qualified Nothing nm) = case (mn, nm) `M.lookup` types env of
Just (_, DataAlias mn' pn') -> (mn', pn')
_ -> (mn, nm)
+
+-- |
+-- Canonicalize a data constructor by resolving any aliases introduced by module imports
+--
+canonicalizeDataConstructor :: ModuleName -> Environment -> Qualified ProperName -> (ModuleName, Ident)
+canonicalizeDataConstructor _ _ (Qualified (Just mn) i) = (mn, Ident $ show i)
+canonicalizeDataConstructor mn env (Qualified Nothing i) = case (mn, i) `M.lookup` dataConstructors env of
+ Just (_, Alias mn' i') -> (mn', i')
+ _ -> (mn, Ident $ show i)
-- |
-- State required for type checking: