Skip to content

Commit c861845

Browse files
authored
Abandon ambiguity resolution on undefined name (#1907)
* Abandon ambiguity resolution on undefined name This has finally annoyed me enough to do something about it. If we get a "no such variable" error there's no point exploring other branches. * Removes spaces from test file One day I'll update the linter to ignore test files. We should really accept literally anything as a possiblity for test files, even if removing the spaces is tidier. * Reset context before throwing in 'successful' Although I don't think this is strictly necessary for a fatal error, we should still for the sake of tidiness reset the state when backtracking.
1 parent 9865765 commit c861845

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

src/TTImp/Elab/Check.idr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,20 @@ successful allowCons ((tm, elab) :: elabs)
580580
put EST est
581581
put MD md
582582
put Ctxt defs
583+
when (abandon err) $ throw err
583584
elabs' <- successful allowCons elabs
584585
pure (Left (tm, err) :: elabs'))
586+
where
587+
-- Some errors, it's not worth trying all the possibilities because
588+
-- something serious has gone wrong, so just give up immediately.
589+
abandon : Error -> Bool
590+
abandon (UndefinedName _ _) = True
591+
abandon (InType _ _ err) = abandon err
592+
abandon (InCon _ _ err) = abandon err
593+
abandon (InLHS _ _ err) = abandon err
594+
abandon (InRHS _ _ err) = abandon err
595+
abandon (AllFailed errs) = any (abandon . snd) errs
596+
abandon _ = False
585597

586598
export
587599
exactlyOne' : {vars : _} ->

tests/Main.idr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ idrisTestsError = MkTestPool "Error messages" [] Nothing
6969
"error006", "error007", "error008", "error009", "error010",
7070
"error011", "error012", "error013", "error014", "error015",
7171
"error016", "error017", "error018", "error019", "error020",
72+
"error021",
7273
-- Parse errors
7374
"perror001", "perror002", "perror003", "perror004", "perror005",
7475
"perror006", "perror007", "perror008", "perror009", "perror010",

tests/idris2/error021/DeepAmbig.idr

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
namespace A
3+
export
4+
x : Bool -> Bool
5+
x = not
6+
7+
namespace B
8+
export
9+
x : Nat -> Bool
10+
x Z = True
11+
x _ = False
12+
13+
%ambiguity_depth 1000
14+
15+
-- There's an undefined name very deep here - if we don't take a shortcut,
16+
-- this shows all the ambiguous branches with the undefined named!
17+
test : Nat -> Bool
18+
test val
19+
= x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
20+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
21+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
22+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
23+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
24+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
25+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
26+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
27+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
28+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
29+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
30+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
31+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
32+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
33+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
34+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
35+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
36+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
37+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
38+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
39+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
40+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
41+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
42+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
43+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
44+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
45+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
46+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
47+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
48+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
49+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
50+
x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ va

tests/idris2/error021/expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1/1: Building DeepAmbig (DeepAmbig.idr)
2+
Error: While processing right hand side of test. Undefined name va.
3+
4+
DeepAmbig:50:59--50:61
5+
46 | x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
6+
47 | x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
7+
48 | x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
8+
49 | x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $
9+
50 | x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ x $ va
10+
^^
11+

tests/idris2/error021/run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rm -rf build
2+
3+
$1 --no-color --console-width 0 --no-banner -Werror --check DeepAmbig.idr
4+

0 commit comments

Comments
 (0)