mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-11-23 19:29:17 +03:00
Apply suggestions from code review
Co-authored-by: Martin Šošić <Martinsos@users.noreply.github.com>
This commit is contained in:
parent
c456ca8d2e
commit
46206c3fb3
@ -1,4 +1,4 @@
|
||||
-- | This module exports the functions necessary typecheck AST from "Analyzer.Parser".
|
||||
-- | This module exports the functions necessary for typechecking the AST from "Analyzer.Parser".
|
||||
-- See the Type Checking section in "docs/wasplang" for the rules type checking follows.
|
||||
--
|
||||
-- See "Analyzer.TypeChecker.Internal" for the implementation of the type checking rules.
|
||||
@ -27,7 +27,7 @@ import Analyzer.TypeChecker.Monad (runT)
|
||||
import Analyzer.TypeChecker.TypeError
|
||||
import Analyzer.TypeDefinitions (TypeDefinitions)
|
||||
|
||||
-- | Checks that an AST conforms to the type rules of Wasp and produces a
|
||||
-- | Checks that an AST conforms to the type rules of Wasp and produces
|
||||
-- an AST labelled with type information.
|
||||
typeCheck :: TypeDefinitions -> AST -> Either TypeError TypedAST
|
||||
typeCheck typeDefs ast = runT typeDefs $ check ast
|
||||
|
@ -185,10 +185,10 @@ weaken typ' expr
|
||||
-- A list can be weakened to @typ@ if
|
||||
-- - @typ@ is of the form @ListType typ'@
|
||||
-- - Every value in the list can be weakened to @typ'@
|
||||
weaken (ListType typ') expr@(List vals _) =
|
||||
fmap (\values -> List values (ListType typ')) $
|
||||
left (\e -> WeakenError (ReasonList e) expr typ') $
|
||||
mapM (weaken typ') vals
|
||||
weaken type'@(ListType elemType') expr@(List elems _) = do
|
||||
elems' <- left (\e -> WeakenError (ReasonList e) expr elemType') $
|
||||
mapM (weaken elemType') elems
|
||||
return $ List elems' type'
|
||||
weaken (DictType typ') expr@(Dict entries _) = do
|
||||
entries' <- mapM weakenEntry entries
|
||||
mapM_ guardHasEntry $ M.toList typ'
|
||||
|
@ -26,7 +26,7 @@ data TypeCoerceReason
|
||||
ReasonEnum
|
||||
| -- | There is no relationship between the types in the coercion
|
||||
ReasonUncoercable
|
||||
| -- | A coercion of the type contained in a list fialed
|
||||
| -- | A coercion of the type contained in a list failed
|
||||
ReasonList TypeError
|
||||
| -- | A coercion failed because a dictionary was missing a key
|
||||
ReasonDictNoKey String
|
||||
|
@ -8,8 +8,8 @@ import Data.Either (isRight)
|
||||
import qualified Data.HashMap.Strict as H
|
||||
import Test.Tasty.Hspec
|
||||
|
||||
spec_Parser :: Spec
|
||||
spec_Parser = do
|
||||
spec_TypeChecker :: Spec
|
||||
spec_TypeChecker = do
|
||||
describe "Analyzer.TypeChecker" $ do
|
||||
describe "typeCheck" $ do
|
||||
it "Type checks a simple, well-typed example" $ do
|
||||
|
Loading…
Reference in New Issue
Block a user