Skip to content

Commit

Permalink
Add dependency on expressions in function default arguments
Browse files Browse the repository at this point in the history
Any function call in a default argument will be requried by callers of
the outer function.
  • Loading branch information
paulcadman authored and janmasrovira committed Oct 24, 2023
1 parent 8e6c1c8 commit ed123ef
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Juvix/Compiler/Internal/Extra/DependencyBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ goFunctionDefHelper f = do
goInstance f
goExpression (Just (f ^. funDefName)) (f ^. funDefType)
goExpression (Just (f ^. funDefName)) (f ^. funDefBody)
mapM_ (goExpression (Just (f ^. funDefName))) (catMaybes (concat (f ^. funDefDefaultSignature ^.. defaultSignature)))

-- constructors of an inductive type depend on the inductive type, not the other
-- way round; an inductive type depends on the types of its constructors
Expand Down
7 changes: 6 additions & 1 deletion test/Compilation/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -387,5 +387,10 @@ tests =
"Test065: Arithmetic simplification"
$(mkRelDir ".")
$(mkRelFile "test065.juvix")
$(mkRelFile "out/test065.out")
$(mkRelFile "out/test065.out"),
posTest
"Test066: Import function with a function call in default argument"
$(mkRelDir "test066")
$(mkRelFile "M.juvix")
$(mkRelFile "out/test066.out")
]
1 change: 1 addition & 0 deletions tests/Compilation/positive/out/test066.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
6 changes: 6 additions & 0 deletions tests/Compilation/positive/test066/M.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module M;

import Stdlib.Prelude open;
import N open;

main : Nat := f;
7 changes: 7 additions & 0 deletions tests/Compilation/positive/test066/N.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module N;

import Stdlib.Prelude open;

mkNat (n : Nat) : Nat := n;

f {a : Nat := mkNat 0} : Nat := a;
Empty file.

0 comments on commit ed123ef

Please sign in to comment.