mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-24 17:44:21 +03:00
Suggestions from code review
This commit is contained in:
parent
6f178115dc
commit
96450aa31d
@ -15,7 +15,7 @@ data Expr
|
||||
| DoubleLiteral Double
|
||||
| BoolLiteral Bool
|
||||
| ExtImport ExtImportName String
|
||||
| Identifier Identifier
|
||||
| Var Identifier
|
||||
| Quoter Identifier String
|
||||
deriving (Eq, Show)
|
||||
|
||||
|
@ -76,7 +76,7 @@ Expr :: { Expr }
|
||||
| double { DoubleLiteral $1 }
|
||||
| true { BoolLiteral True }
|
||||
| false { BoolLiteral False }
|
||||
| ident { Identifier $1 }
|
||||
| ident { Var $1 }
|
||||
|
||||
Dict :: { Expr }
|
||||
: '{' DictEntries '}' { Dict $2 }
|
||||
|
@ -79,7 +79,7 @@ inferExprType (P.IntegerLiteral i) = return $ IntegerLiteral i
|
||||
inferExprType (P.DoubleLiteral d) = return $ DoubleLiteral d
|
||||
inferExprType (P.BoolLiteral b) = return $ BoolLiteral b
|
||||
inferExprType (P.ExtImport n s) = return $ ExtImport n s
|
||||
inferExprType (P.Identifier ident) =
|
||||
inferExprType (P.Var ident) =
|
||||
lookupType ident >>= \case
|
||||
Nothing -> throw $ UndefinedIdentifier ident
|
||||
Just typ -> return $ Var ident typ
|
||||
|
@ -2,13 +2,14 @@
|
||||
|
||||
module Analyzer.TypeChecker.Monad
|
||||
( TypeChecker,
|
||||
Bindings,
|
||||
lookupType,
|
||||
setType,
|
||||
throw,
|
||||
lookupDeclType,
|
||||
runWithBound,
|
||||
run,
|
||||
-- Exported for testing
|
||||
Bindings,
|
||||
runWithBound,
|
||||
)
|
||||
where
|
||||
|
||||
|
@ -30,7 +30,7 @@ spec_Parser = do
|
||||
("real", DoubleLiteral 3.14),
|
||||
("yes", BoolLiteral True),
|
||||
("no", BoolLiteral False),
|
||||
("ident", Identifier "Wasp")
|
||||
("ident", Var "Wasp")
|
||||
]
|
||||
]
|
||||
parse source `shouldBe` Right ast
|
||||
|
@ -99,11 +99,11 @@ spec_Internal = do
|
||||
it "Types identifier as the type in the bindings" $ do
|
||||
forAll chooseType $ \typ ->
|
||||
let bindings = H.singleton "var" typ
|
||||
actual = exprType <$> inferExprType' bindings (P.Identifier "var")
|
||||
actual = exprType <$> inferExprType' bindings (P.Var "var")
|
||||
in actual == Right typ
|
||||
it "Fails to type check identifiers not given a type in the bindings" $ do
|
||||
let bindings = H.empty
|
||||
let actual = exprType <$> inferExprType' bindings (P.Identifier "pi")
|
||||
let actual = exprType <$> inferExprType' bindings (P.Var "pi")
|
||||
let expected = Left $ UndefinedIdentifier "pi"
|
||||
actual `shouldBe` expected
|
||||
|
||||
|
@ -60,7 +60,7 @@ spec_TypeChecker = do
|
||||
let actual = typeCheck typeDefs ast
|
||||
actual `shouldSatisfy` isRight
|
||||
it "Type checks an existing enum value" $ do
|
||||
let ast = P.AST [P.Decl "food" "Cucumber" (P.Identifier "Dill")]
|
||||
let ast = P.AST [P.Decl "food" "Cucumber" (P.Var "Dill")]
|
||||
let typeDefs =
|
||||
TD.TypeDefinitions
|
||||
{ TD.declTypes = H.singleton "food" (TD.DeclType "food" (EnumType "flavor")),
|
||||
|
Loading…
Reference in New Issue
Block a user