Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in arity checker with pi types #2300

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,8 @@ checkFunctionClause ari cl = do
simplelambda :: a
simplelambda = error "simple lambda expressions are not supported by the arity checker"

withLocalTypeVar :: Members '[Reader LocalVars] r => VarName -> Sem r a -> Sem r a
withLocalTypeVar v = withLocalVar v ArityUnit

withLocalVar :: Members '[Reader LocalVars] r => VarName -> Arity -> Sem r a -> Sem r a
withLocalVar v = local . withArity v
withLocalVar :: Members '[Reader LocalVars] r => Arity -> VarName -> Sem r a -> Sem r a
withLocalVar ari v = local (withArity v ari)

withEmptyLocalVars :: Sem (Reader LocalVars ': r) a -> Sem r a
withEmptyLocalVars = runReader emptyLocalVars
Expand Down Expand Up @@ -547,7 +544,8 @@ checkExpression hintArity expr = case expr of
goFunction :: Function -> Sem r Function
goFunction (Function l r) = do
l' <- goFunctionParameter l
r' <- maybe id withLocalTypeVar (l ^. paramName) (checkType r)
let ari = typeArity (l' ^. paramType)
r' <- maybe id (withLocalVar ari) (l ^. paramName) (checkType r)
return (Function l' r')
where
goFunctionParameter :: FunctionParameter -> Sem r FunctionParameter
Expand Down
6 changes: 5 additions & 1 deletion test/Typecheck/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ tests =
posTest
"Omit Type annotation"
$(mkRelDir ".")
$(mkRelFile "OmitType.juvix")
$(mkRelFile "OmitType.juvix"),
posTest
"Issue 2296 (Pi types with lhs arity other than unit)"
$(mkRelDir "issue2296")
$(mkRelFile "M.juvix")
]
<> [ compilationTest t | t <- Compilation.tests
]
4 changes: 4 additions & 0 deletions tests/positive/issue2296/M.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module M;

f : (F : Type → Type) → (A : Type) → F A → F A;
f _ _ x := x;
4 changes: 4 additions & 0 deletions tests/positive/issue2296/juvix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies:
- .juvix-build/stdlib/
name: issue2296
version: 0.0.0
Loading