Skip to content

Commit

Permalink
Fix bug in arity checker with pi types (#2300)
Browse files Browse the repository at this point in the history
All variables bound in a pi type were assumed to be of arity unit. This
pr fixes that.

- Closes #2296
  • Loading branch information
janmasrovira authored Aug 22, 2023
1 parent 63a94bb commit d57f1a3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
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

0 comments on commit d57f1a3

Please sign in to comment.