on master help sign in
Add test for impossible in lambda and case
commitfc9839cd0a2dcbee3b518153d756b30a13028410 authorMelvar Chen <Melvar.Chen@googlemail.com> dateFri 27 Mar 2015, 20:11 (12 years ago) parentffa4223
5 files changed+58
idris.cabal+3 test/totality009/TestLambdaImpossible.idr+29 test/totality009/TestLambdaPossible.idr+13 test/totality009/expected+8 test/totality009/run+5
idris.cabal+3
@@ -609,6 +609,9 @@ Extra-source-files:
609609 test/totality008/run
610610 test/totality008/*.idr
611611 test/totality008/expected
612+ test/totality009/run
613+ test/totality009/*.idr
614+ test/totality009/expected
612615
613616 test/tutorial001/run
614617 test/tutorial001/*.idr
test/totality009/TestLambdaImpossible.idrnew file+29
@@ -0,0 +1,29 @@
1+module TestLambdaImpossible
2+
3+%default total
4+
5+eqBool : (x, y : Bool) -> Dec (x = y)
6+eqBool False False = Yes Refl
7+eqBool False True = No (\(Refl) impossible)
8+eqBool True False = No (\(Refl) impossible)
9+eqBool True True = Yes Refl
10+
11+data Elem : {a : Type} -> a -> Prelude.List.List a -> Type where
12+ Here : {a : Type} -> {x : a} -> {xs : List a} -> Elem x (x :: xs)
13+ There : {a : Type} -> {x, y : a} -> {xs : List a} -> Elem x xs -> Elem x (y :: xs)
14+
15+notHereNotThere : Not (x = y) -> Not (Elem x xs) -> Not (Elem x (y :: xs))
16+notHereNotThere notEq notElem Here = notEq Refl
17+notHereNotThere notEq notElem (There elem) = notElem elem
18+
19+decElem : DecEq a => (x : a) -> (xs : List a) -> Dec (Elem x xs)
20+decElem x [] = No (\Here impossible)
21+decElem x (y :: xs) with (decEq x y)
22+ decElem x (x :: xs) | (Yes Refl) = Yes Here
23+ decElem x (y :: xs) | (No notHere) with (decElem x xs)
24+ decElem x (y :: xs) | (No notHere) | (Yes prf) = Yes (There prf)
25+ decElem x (y :: xs) | (No notHere) | (No notThere) = No $ notHereNotThere notHere notThere
26+
27+notEta : ((a : Type) -> (b : Type) -> (f : a -> b) -> f = (\x => f x)) -> Void
28+notEta eta = case eta Nat Nat id of
29+ Refl impossible
test/totality009/TestLambdaPossible.idrnew file+13
@@ -0,0 +1,13 @@
1+||| Some functions that should be non-total, as detected with --warnpartial
2+module TestLambdaPossible
3+
4+data Nool : Bool -> Type where
5+ Flase : Nool False
6+ Ture : Nool True
7+
8+wrongPossible : Nool True -> Bool
9+wrongPossible = (\Flase impossible)
10+
11+wrongPossible' : Nool True -> Bool
12+wrongPossible' x = case x of
13+ Flase impossible
test/totality009/expectednew file+8
@@ -0,0 +1,8 @@
1+TestLambdaPossible.idr:9:25:Warning - TestLambdaPossible.case block in wrongPossible is not total as there are missing cases
2+TestLambdaPossible.idr:9:1:Warning - TestLambdaPossible.wrongPossible is possibly not total due to: TestLambdaPossible.case block in wrongPossible
3+TestLambdaPossible.idr:12:25:Warning - TestLambdaPossible.case block in wrongPossible' is not total as there are missing cases
4+TestLambdaPossible.idr:12:1:Warning - TestLambdaPossible.wrongPossible' is possibly not total due to: TestLambdaPossible.case block in wrongPossible'
5+TestLambdaPossible.idr:9:15:Warning - TestLambdaPossible.case block in wrongPossible is not total as there are missing cases
6+TestLambdaPossible.idr:9:1:Warning - TestLambdaPossible.wrongPossible is possibly not total due to: TestLambdaPossible.case block in wrongPossible
7+TestLambdaPossible.idr:12:16:Warning - TestLambdaPossible.case block in wrongPossible' is not total as there are missing cases
8+TestLambdaPossible.idr:12:1:Warning - TestLambdaPossible.wrongPossible' is possibly not total due to: TestLambdaPossible.case block in wrongPossible'
test/totality009/runnew file+5
@@ -0,0 +1,5 @@
1+#!/usr/bin/env bash
2+OPTS="--consolewidth infinite --nocolour"
3+idris "$@" $OPTS --check TestLambdaImpossible
4+idris "$@" $OPTS --check --warnpartial TestLambdaPossible
5+rm -f *.ibc