Skip to content

Commit bdc6e38

Browse files
committed
[ fix ] Check totality after all declarations
1 parent 153d945 commit bdc6e38

File tree

12 files changed

+108
-60
lines changed

12 files changed

+108
-60
lines changed

CHANGELOG_NEXT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ should target this file (`CHANGELOG_NEXT`).
6666
`impossible` clause.
6767
* Do not inline `Core.sequence`, because it is recursively defined.
6868
* Fixed coverage checker issues (#1800, #1998, #2318, #2822, #3679).
69+
* Fixed totality checking in namespace and mutual blocks (#2868, #3692).
6970

7071
### Building/Packaging changes
7172

src/Idris/ProcessIdr.idr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ processDecl decl
8787
pure [err])
8888

8989
processDecls decls
90-
= do xs <- concat <$> traverse processDecl decls
90+
= do errs <- concat <$> traverse processDecl decls
9191
Nothing <- checkDelayedHoles
92-
| Just err => pure (if null xs then [err] else xs)
93-
errs <- logTime 3 ("Totality check overall") getTotalityErrors
94-
pure (xs ++ errs)
92+
| Just err => pure (if null errs then [err] else errs)
93+
pure errs
9594

9695
readModule : {auto c : Ref Ctxt Defs} ->
9796
{auto u : Ref UST UState} ->
@@ -388,6 +387,9 @@ processMod sourceFileName ttcFileName msg sourcecode origin
388387
setNS (miAsNamespace ns)
389388
errs <- logTime 2 "Processing decls" $
390389
processDecls (decls mod)
390+
totErrs <- logTime 3 ("Totality check overall")
391+
getTotalityErrors
392+
let errs = errs ++ totErrs
391393
-- coreLift $ gc
392394

393395
when (isNil errs) $
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bad : Bool -> ()
2+
bad True = ()
3+
4+
namespace X
5+
foo : ()
6+
foo = ()
7+
8+
mutual
9+
bar : ()
10+
bar = baz
11+
12+
baz : ()
13+
baz = bar
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1/1: Building Issue3692 (Issue3692.idr)
2+
Error: bad is not covering.
3+
4+
Issue3692:1:1--1:17
5+
1 | bad : Bool -> ()
6+
^^^^^^^^^^^^^^^^
7+
8+
Missing cases:
9+
bad False
10+

tests/idris2/error/error034/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
. ../../../testutils.sh
2+
3+
check Issue3692.idr

tests/idris2/termination/termination001/expected

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,6 @@ AgdaIssue6059:23:3--23:21
1111

1212
Error: g is not total, possibly not terminating due to recursive path Main.f -> Main.f -> Main.g
1313

14-
AgdaIssue6059:31:3--31:32
15-
27 | -- Base cases:
16-
28 | f (MkD 0 0) = ()
17-
29 | f (MkD 0 1) = ()
18-
30 |
19-
31 | g : (h : Nat -> D) -> P (h 2)
20-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
22-
Error: f is not total, possibly not terminating due to call to Main.g
23-
24-
AgdaIssue6059:23:3--23:21
25-
19 | lem 0 = Refl
26-
20 | lem (S n) = Refl
27-
21 |
28-
22 | mutual
29-
23 | f : (x : D) -> P x
30-
^^^^^^^^^^^^^^^^^^
31-
32-
Error: g is not total, possibly not terminating due to recursive path Main.f -> Main.f -> Main.g
33-
3414
AgdaIssue6059:31:3--31:32
3515
27 | -- Base cases:
3616
28 | f (MkD 0 0) = ()

tests/idris2/total/total011/expected

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,3 @@ Issue1828:8:3--8:14
6262
8 | dummy : Nat
6363
^^^^^^^^^^^
6464

65-
Error: caseTest is not total, possibly not terminating due to call to Main.dummy
66-
67-
Issue1828:4:3--4:25
68-
1 | %default total
69-
2 |
70-
3 | mutual
71-
4 | caseTest : Nat -> Bool
72-
^^^^^^^^^^^^^^^^^^^^^^
73-
74-
Error: dummy is not total, possibly not terminating due to recursive path Main.caseTest -> Main.dummy
75-
76-
Issue1828:8:3--8:14
77-
4 | caseTest : Nat -> Bool
78-
5 | caseTest p with (dummy)
79-
6 | caseTest p | _ = True
80-
7 |
81-
8 | dummy : Nat
82-
^^^^^^^^^^^
83-

tests/idris2/total/total012/expected

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,6 @@ Issue1828:2:3--2:25
1212

1313
Error: dummy is not total, possibly not terminating due to recursive path Main.caseTest -> Main.dummy
1414

15-
Issue1828:6:3--6:14
16-
2 | caseTest : Nat -> Bool
17-
3 | caseTest p with (dummy)
18-
4 | caseTest p | _ = True
19-
5 |
20-
6 | dummy : Nat
21-
^^^^^^^^^^^
22-
23-
Error: caseTest is not total, possibly not terminating due to call to Main.dummy
24-
25-
Issue1828:2:3--2:25
26-
1 | mutual
27-
2 | caseTest : Nat -> Bool
28-
^^^^^^^^^^^^^^^^^^^^^^
29-
30-
Error: dummy is not total, possibly not terminating due to recursive path Main.caseTest -> Main.dummy
31-
3215
Issue1828:6:3--6:14
3316
2 | caseTest : Nat -> Bool
3417
3 | caseTest p with (dummy)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
%default total
2+
3+
namespace Foo
4+
public export
5+
total
6+
foo : ()
7+
8+
namespace Bar
9+
public export
10+
total
11+
bar : ()
12+
13+
namespace Foo
14+
foo = bar
15+
16+
namespace Bar
17+
bar = foo
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
%default total
2+
3+
namespace Foo
4+
public export
5+
foo : Void
6+
7+
namespace Bar
8+
public export
9+
bar : Void
10+
bar = foo
11+
12+
namespace Foo
13+
foo = bar
14+
15+
boom : Void
16+
boom = foo

0 commit comments

Comments
 (0)