on master help sign in
Check that main is a Signal or (Signal Element), add tests for this case
commit70f1242bd0b7a7d3a8b39c843d578032321f7efc authorEvan Czaplicki <info@elm-lang.org> dateMon 19 Aug 2013, 17:47 (13 years ago) parent4da7588
5 files changed+21−7
compiler/Type/ExtraChecks.hs+15−5 compiler/Type/Inference.hs+2−1 tests/Main.hs+1−1 tests/bad/BBTArgs+1 tests/bad/NonElementMain.elm+2
compiler/Type/ExtraChecks.hs+15−5
@@ -1,15 +1,25 @@
11-- This module contains checks to be run *after* type inference has
22-- completed successfully. At that point we still need to do occurs
33-- checks and ensure that `main` has an acceptable type.
4−module Type.ExtraChecks where
4+module Type.ExtraChecks (extraChecks) where
55
66import qualified Data.Map as Map
77import Type.State (Env)
8+import Type.PrettyPrint ( pretty, ParensWhen(Never) )
9+import Text.PrettyPrint as P
810
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
1015mainCheck env =
1116 case Map.lookup "main" env of
12− Nothing -> return (Right env)
13− Just var -> return (Right env)
17+ Nothing -> 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)" ] ]
1423
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)
1414import SourceSyntax.PrettyPrint
1515import Text.PrettyPrint
1616import qualified Type.State as TS
17+import Type.ExtraChecks (extraChecks)
1718import Control.Monad.State
1819import Control.Arrow (second)
1920import Transform.SortDefinitions as Sort
@@ -46,6 +47,6 @@ infer interfaces modul = unsafePerformIO $ do
4647 state <- execStateT (Solve.solve constraint) TS.initialState
4748 let errors = TS.sErrors state
4849 if null errors
49− then return $ Right (Map.difference (TS.sSavedEnv state) header)
50+ then return . extraChecks $ Map.difference (TS.sSavedEnv state) header
5051 else Left `fmap` sequence (reverse errors)
5152
tests/Main.hs+1−1
@@ -9,7 +9,7 @@ import Test.Framework.BlackBoxTest
99main :: IO ()
1010main = do
1111 args <- getArgs
12− tests <- blackBoxTests "tests/good" "dist/build/elm/elm" ".elm" bbtArgs
12+ tests <- blackBoxTests "tests" "dist/build/elm/elm" ".elm" bbtArgs
1313 code <- runTestWithArgs args tests
1414 removeDirectoryRecursive "cache"
1515 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