1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00

Add type annotation to case expression (#1849)

This commit is contained in:
janmasrovira 2023-02-16 12:54:53 +01:00 committed by GitHub
parent dd8457d097
commit ca4926527e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 0 deletions

View File

@ -250,6 +250,7 @@ instance HasExpressions Case where
leafExpressions f l = do
_caseBranches :: NonEmpty CaseBranch <- traverse (leafExpressions f) (l ^. caseBranches)
_caseExpression <- leafExpressions f (l ^. caseExpression)
_caseExpressionType <- traverse (leafExpressions f) (l ^. caseExpressionType)
pure Case {..}
where
_caseParens = l ^. caseParens

View File

@ -155,6 +155,8 @@ instance Hashable CaseBranch
data Case = Case
{ _caseExpression :: Expression,
-- | The typechecker fills this field
_caseExpressionType :: Maybe Expression,
_caseBranches :: NonEmpty CaseBranch,
_caseParens :: Bool
}

View File

@ -346,6 +346,7 @@ goCase c = do
_caseExpression <- goExpression (c ^. Abstract.caseExpression)
_caseBranches <- mapM goCaseBranch (c ^. Abstract.caseBranches)
let _caseParens = c ^. Abstract.caseParens
_caseExpressionType :: Maybe Expression = Nothing
return Case {..}
goCaseBranch :: Members '[NameIdGen] r => Abstract.CaseBranch -> Sem r CaseBranch

View File

@ -356,6 +356,7 @@ checkCase ari l = do
_caseBranches <- mapM checkCaseBranch (l ^. caseBranches)
_caseExpression <- checkExpression ArityUnit (l ^. caseExpression)
let _caseParens = l ^. caseParens
_caseExpressionType :: Maybe Expression = Nothing
return Case {..}
where
checkCaseBranch :: CaseBranch -> Sem r CaseBranch

View File

@ -555,6 +555,7 @@ inferExpression' hint e = case e of
Just hi -> return hi
typedCaseExpression <- inferExpression' Nothing (c ^. caseExpression)
let _caseExpression = typedCaseExpression ^. typedExpression
_caseExpressionType = Just (typedCaseExpression ^. typedType)
goBranch :: CaseBranch -> Sem r CaseBranch
goBranch b =
traverseOf