on master help sign in
Check that main is a Signal or (Signal Element), add tests for this case
70f1242Evan Czaplicki
compiler/Type/ExtraChecks.hs+15−5
@@ -1,15 +1,25 @@
1-- This module contains checks to be run *after* type inference has
1-- This module contains checks to be run *after* type inference has
2-- completed successfully. At that point we still need to do occurs
2-- completed successfully. At that point we still need to do occurs
3-- checks and ensure that `main` has an acceptable type.
3-- checks and ensure that `main` has an acceptable type.
4−module Type.ExtraChecks where
4+module Type.ExtraChecks (extraChecks) where
5
5
6import qualified Data.Map as Map
6import qualified Data.Map as Map
7import Type.State (Env)
7import Type.State (Env)
8+import Type.PrettyPrint ( pretty, ParensWhen(Never) )
9+import Text.PrettyPrint as P
8
10
9−mainCheck :: Env -> IO (Either String Env)
11+extraChecks :: Env -> Either [P.Doc] Env
12+extraChecks env = occursCheck =<< mainCheck env
13+
14+mainCheck :: Env -> Either [P.Doc] Env
10mainCheck env =
15mainCheck env =
11 case Map.lookup "main" env of
16 case Map.lookup "main" env of
12− Nothing -> return (Right env)
17+ Nothing -> Right env
13− Just var -> return (Right env)
18+ Just var
19+ | P.render (pretty Never var) `elem` ["Element","Signal Element"] -> Right env
20+ | otherwise ->
21+ Left [ P.vcat [ P.text "Type Error:"
22+ , P.text "'main' must be an Element or a (Signal Element)" ] ]
14
23
15−occursCheck = undefined
24+occursCheck :: Env -> Either [P.Doc] Env
25+occursCheck env = return env
compiler/Type/Inference.hs+2−1
@@ -14,6 +14,7 @@ import SourceSyntax.Location (Located, noneNoDocs)
14import SourceSyntax.PrettyPrint
14import SourceSyntax.PrettyPrint
15import Text.PrettyPrint
15import Text.PrettyPrint
16import qualified Type.State as TS
16import qualified Type.State as TS
17+import Type.ExtraChecks (extraChecks)
17import Control.Monad.State
18import Control.Monad.State
18import Control.Arrow (second)
19import Control.Arrow (second)
19import Transform.SortDefinitions as Sort
20import Transform.SortDefinitions as Sort
@@ -46,6 +47,6 @@ infer interfaces modul = unsafePerformIO $ do
46 state <- execStateT (Solve.solve constraint) TS.initialState
47 state <- execStateT (Solve.solve constraint) TS.initialState
47 let errors = TS.sErrors state
48 let errors = TS.sErrors state
48 if null errors
49 if null errors
49− then return $ Right (Map.difference (TS.sSavedEnv state) header)
50+ then return . extraChecks $ Map.difference (TS.sSavedEnv state) header
50 else Left `fmap` sequence (reverse errors)
51 else Left `fmap` sequence (reverse errors)
51
52
tests/Main.hs+1−1
@@ -9,7 +9,7 @@ import Test.Framework.BlackBoxTest
9main :: IO ()
9main :: IO ()
10main = do
10main = do
11 args <- getArgs
11 args <- getArgs
12− tests <- blackBoxTests "tests/good" "dist/build/elm/elm" ".elm" bbtArgs
12+ tests <- blackBoxTests "tests" "dist/build/elm/elm" ".elm" bbtArgs
13 code <- runTestWithArgs args tests
13 code <- runTestWithArgs args tests
14 removeDirectoryRecursive "cache"
14 removeDirectoryRecursive "cache"
15 removeDirectoryRecursive "build"
15 removeDirectoryRecursive "build"
tests/bad/BBTArgsnew file+1
@@ -0,0 +1 @@
1+Fail
tests/bad/NonElementMain.elmnew file+2
@@ -0,0 +1,2 @@
1+
2+main = 42