on master help sign in
Coverage checker fix

Make sure it looks at all arguments - sometimes applications are nested by the elaborator and these should be flattened. Fixes #2129

commitfcba396622bc353a79e5ec5feaa03c0207b53300 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSun 6 Sep 2015, 13:28 (11 years ago) parentc931eff
5 files changed+49−4
idris.cabal+3 src/Idris/Coverage.hs+8−4 test/totality010/expected+4 test/totality010/run+3 test/totality010/totality010.idr+31
idris.cabal+3
@@ -708,6 +708,9 @@ Extra-source-files:
708708 test/totality009/run
709709 test/totality009/*.idr
710710 test/totality009/expected
711+ test/totality010/run
712+ test/totality010/*.idr
713+ test/totality010/expected
711714
712715 test/tutorial001/run
713716 test/tutorial001/*.idr
src/Idris/Coverage.hs+8−4
@@ -54,16 +54,16 @@ mkPatTm t = do i <- getIState
5454genClauses :: FC -> Name -> [Term] -> [PTerm] -> Idris [PTerm]
5555genClauses fc n xs given
5656 = do i <- getIState
57− let lhs_tms = map (\x -> delab' i x True True) xs
57+ let lhs_tms = map (\x -> flattenArgs $ delab' i x True True) xs
5858 -- if a placeholder was given, don't bother generating cases for it
5959 let lhs_tms' = zipWith mergePlaceholders lhs_tms
60− (map (stripUnmatchable i) given)
60+ (map (stripUnmatchable i) (map flattenArgs given))
6161 let lhss = map pUnApply lhs_tms'
6262
6363 let argss = transpose lhss
6464 let all_args = map (genAll i) argss
6565 logLvl 5 $ "COVERAGE of " ++ show n
66− logLvl 5 $ show lhss
66+ logLvl 5 $ show (lhs_tms, lhss)
6767 logLvl 5 $ show (map length argss) ++ "\n" ++ show (map length all_args)
6868 logLvl 10 $ show argss ++ "\n" ++ show all_args
6969 logLvl 3 $ "Original: \n" ++
@@ -89,9 +89,13 @@ genClauses fc n xs given
8989 | (f, args) <- unApply term = map (\t -> delab' i t True True) args
9090 | otherwise = []
9191
92− pUnApply (PApp _ _ args) = map getTm args
92+ pUnApply (PApp _ f args) = map getTm args
9393 pUnApply _ = []
9494
95+ flattenArgs (PApp fc (PApp _ f as) as')
96+ = flattenArgs (PApp fc f (as ++ as'))
97+ flattenArgs t = t
98+
9599 -- Return whether the given clause matches none of the input clauses
96100 -- (xs)
97101 noMatch i tm = all (\x -> case matchClause i (stripUnmatchable i (delab' i x True True)) tm of
test/totality010/expectednew file+4
@@ -0,0 +1,4 @@
1+totality010.idr:27:1:
2+Main.evenNotS is not total as there are missing cases
3+totality010.idr:30:1:
4+Main.bad is possibly not total due to: Main.evenNotS
test/totality010/runnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+idris $@ totality010.idr --check
3+rm -f *.ibc
test/totality010/totality010.idrnew file+31
@@ -0,0 +1,31 @@
1+%default total
2+
3+%default total
4+succNotLTE' : (LTE (S x) x) -> Void
5+succNotLTE' {x = Z} prf = succNotLTEzero prf
6+succNotLTE' {x = (S k)} (LTESucc prf) = succNotLTE' prf
7+
8+succNotLTE : Not (LTE (S x) x)
9+succNotLTE = succNotLTE'
10+
11+succNotLTE2 : Not (LTE (S x) x)
12+succNotLTE2 {x = Z} prf = succNotLTEzero prf
13+succNotLTE2 {x = (S k)} (LTESucc prf) = succNotLTE prf
14+
15+-- a defective even-odd definition allows me to prove bottom
16+
17+mutual
18+ data Even : Nat -> Type where
19+ ZeroEven : Even Z
20+ MkEven : Odd n -> Even (S n)
21+ MkBad : Even n -> Even (S n)
22+
23+ data Odd : Nat -> Type where
24+ MkOdd : Even n -> Odd (S n)
25+
26+evenNotS : Even n -> Not (Even (S n))
27+evenNotS MkEven ZeroEven impossible
28+
29+bad : Void
30+bad = evenNotS ZeroEven $ MkBad ZeroEven
31+