@@ -541,11 +541,6 @@ infer' (Var var) = do
541541 dicts <- getTypeClassDictionaries
542542 return $ TypedValue True (foldl App (Var var) (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) ty'
543543 _ -> return $ TypedValue True (Var var) ty
544−infer' (Block ss) = do
545− ret <- fresh
546− (allCodePathsReturn, _, ss') <- checkBlock M.empty ret ss
547− guardWith "Block is missing a return statement" allCodePathsReturn
548− return $ TypedValue True (Block ss') ret
549544infer' v@(Constructor c) = do
550545 env <- getEnv
551546 Just moduleName <- checkCurrentModule <$> get
@@ -670,77 +665,6 @@ assignVariable name = do
670665 Just _ -> UnifyT . lift . throwError $ "Variable with name " ++ show name ++ " already exists."
671666 _ -> return ()
672667
673−-- |
674−-- Check the type of the return values of a statement, returning whether or not the statement returns on
675−-- all code paths
676−--
677−checkStatement :: M.Map Ident Type -> Type -> Statement -> UnifyT Type Check (Bool, M.Map Ident Type, Statement)
678−checkStatement mass _ (VariableIntroduction name val) = do
679− assignVariable name
680− val'@(TypedValue _ _ t) <- infer val
681− return (False, M.insert name t mass, VariableIntroduction name val')
682−checkStatement mass _ (Assignment ident val) = do
683− val'@(TypedValue _ _ t) <- infer val
684− case M.lookup ident mass of
685− Nothing -> throwError $ "No local variable with name " ++ show ident
686− Just ty -> do t =?= ty
687− return (False, mass, Assignment ident val')
688−checkStatement mass ret (While val inner) = do
689− val' <- check val tyBoolean
690− (allCodePathsReturn, _, inner') <- checkBlock mass ret inner
691− return (allCodePathsReturn, mass, While val' inner')
692−checkStatement mass ret (If ifst) = do
693− (allCodePathsReturn, ifst') <- checkIfStatement mass ret ifst
694− return (allCodePathsReturn, mass, If ifst')
695−checkStatement mass ret (For ident start end inner) = do
696− Just moduleName <- checkCurrentModule <$> get
697− assignVariable ident
698− start' <- check start tyNumber
699− end' <- check end tyNumber
700− (allCodePathsReturn, _, inner') <- bindLocalVariables moduleName [(ident, tyNumber)] $ checkBlock mass ret inner
701− return (allCodePathsReturn, mass, For ident start' end' inner')
702−checkStatement mass ret (Return val) = do
703− val' <- check val ret
704− return (True, mass, Return (TypedValue True val' ret))
705−
706−-- |
707−-- Check the type of an if-then-else statement
708−--
709−checkIfStatement :: M.Map Ident Type -> Type -> IfStatement -> UnifyT Type Check (Bool, IfStatement)
710−checkIfStatement mass ret (IfStatement val thens Nothing) = do
711− val' <- check val tyBoolean
712− (_, _, thens') <- checkBlock mass ret thens
713− return (False, IfStatement val' thens' Nothing)
714−checkIfStatement mass ret (IfStatement val thens (Just elses)) = do
715− val' <- check val tyBoolean
716− (allCodePathsReturn1, _, thens') <- checkBlock mass ret thens
717− (allCodePathsReturn2, elses') <- checkElseStatement mass ret elses
718− return (allCodePathsReturn1 && allCodePathsReturn2, IfStatement val' thens' (Just elses'))
719−
720−-- |
721−-- Check the type of an else statement
722−--
723−checkElseStatement :: M.Map Ident Type -> Type -> ElseStatement -> UnifyT Type Check (Bool, ElseStatement)
724−checkElseStatement mass ret (Else elses) = do
725− (allCodePathsReturn, _, elses') <- checkBlock mass ret elses
726− return (allCodePathsReturn, Else elses')
727−checkElseStatement mass ret (ElseIf ifst) = (id *** ElseIf) <$> checkIfStatement mass ret ifst
728−
729−-- |
730−-- Check the type of the return value of a block of statements
731−--
732−checkBlock :: M.Map Ident Type -> Type -> [Statement] -> UnifyT Type Check (Bool, M.Map Ident Type, [Statement])
733−checkBlock mass _ [] = return (False, mass, [])
734−checkBlock mass ret (s:ss) = do
735− Just moduleName <- checkCurrentModule <$> get
736− (b1, mass1, s') <- checkStatement mass ret s
737− bindLocalVariables moduleName (M.toList mass1) $ case (b1, ss) of
738− (True, []) -> return (True, mass1, [s'])
739− (True, _) -> throwError "Unreachable code"
740− (False, ss') -> do
741− (b, m, ss'') <- checkBlock mass1 ret ss'
742− return (b, m, s':ss'')
743−
744668-- |
745669-- Generate a new skolem constant
746670--
@@ -876,10 +800,6 @@ check' (Accessor prop val) ty = do
876800 rest <- fresh
877801 val' <- check val (Object (RCons prop ty rest))
878802 return $ TypedValue True (Accessor prop val') ty
879−check' (Block ss) ret = do
880− (allCodePathsReturn, _, ss') <- checkBlock M.empty ret ss
881− guardWith "Block is missing a return statement" allCodePathsReturn
882− return $ TypedValue True (Block ss') ret
883803check' (Constructor c) ty = do
884804 env <- getEnv
885805 Just moduleName <- checkCurrentModule <$> get