Skip to content

Commit

Permalink
[ fix ] compile time typecase for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dunhamsteve authored and gallais committed Jul 2, 2024
1 parent 22c25e9 commit efce152
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Core/Normalise/Eval.idr
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,18 @@ parameters (defs : Defs, topopts : EvalOpts)
-- Type of type matching, in typecase
tryAlt env loc opts fc stk (NType _ _) (ConCase (UN (Basic "Type")) tag [] sc)
= evalTree env loc opts fc stk sc
tryAlt env loc opts fc stk (NType _ _) (ConCase _ _ _ _)
= pure NoMatch
-- Arrow matching, in typecase
tryAlt {more}
env loc opts fc stk (NBind pfc x (Pi fc' r e aty) scty) (ConCase (UN (Basic "->")) tag [s,t] sc)
= evalConAlt {more} env loc opts fc stk [s,t]
[aty,
MkNFClosure opts env (NBind pfc x (Lam fc' r e aty) scty)]
sc
tryAlt {more}
env loc opts fc stk (NBind pfc x (Pi fc' r e aty) scty) (ConCase nm tag args sc)
= pure NoMatch
-- Delay matching
tryAlt env loc opts fc stk (NDelay _ _ ty arg) (DelayCase tyn argn sc)
= evalTree env (ty :: arg :: loc) opts fc stk sc
Expand Down
7 changes: 7 additions & 0 deletions tests/idris2/evaluator/evaluator005/TypeCase.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data The : (a : Type) -> a -> Type where
Is : (x : a) -> The a x

tcase : Type -> Type
tcase (The a _) = a
tcase a = a

4 changes: 4 additions & 0 deletions tests/idris2/evaluator/evaluator005/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1/1: Building TypeCase (TypeCase.idr)
Main> Int -> Int
Main> Type
Main> Bye for now!
3 changes: 3 additions & 0 deletions tests/idris2/evaluator/evaluator005/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tcase (Int -> Int)
tcase Type
:q
3 changes: 3 additions & 0 deletions tests/idris2/evaluator/evaluator005/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
. ../../../testutils.sh

idris2 TypeCase.idr < input

0 comments on commit efce152

Please sign in to comment.