Skip to content

Commit ebb75fb

Browse files
committed
Improve error message for missing witness.
1 parent 7d76fc7 commit ebb75fb

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

src/checker/Pulse.Checker.Prover.fst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ let intro_exists (g: env) (frame: slprop) (u: universe) (b: binder) (body: slpro
303303
let frame_typ : tot_typing g frame tm_slprop = RU.magic () in // implied by t2_typing
304304
let binder_ty_typ : tot_typing g b.binder_ty (tm_type u) = RU.magic() in // implied by t2_typing
305305
let tm_ex_typ : tot_typing g (tm_exists_sl u b body) tm_slprop = RU.magic() in // implied by t2_typing
306-
// TODO: improve error message below. this will e.g. fail if we cannot solve e using unification
307-
let e_typ = core_check_term g e T.E_Ghost b.binder_ty in
306+
let e_typ = core_check_term' g e T.E_Ghost b.binder_ty (fun _ -> let open Pulse.PP in
307+
[text "Cannot find witness for" ^/^ pp (tm_exists_sl u b body)]) in
308308
let h1: tot_typing g (tm_star frame (comp_pre (comp_intro_exists u b body e))) tm_slprop = RU.magic () in
309309
let h2: slprop_equiv g (tm_star frame (comp_pre (comp_intro_exists u b body e))) (tm_star frame (open_term' body e 0)) = RU.magic () in
310310
let h3: slprop_equiv g (tm_star (comp_post (comp_intro_exists u b body e)) frame) (tm_star frame (tm_exists_sl u b body)) = RU.magic () in

src/checker/Pulse.Checker.Pure.fst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ let core_compute_term_type (g:env) (t:term)
466466
in
467467
RU.record_stats "Pulse.core_compute_term_type" aux
468468

469-
let core_check_term g e eff t
469+
let core_check_term' g e eff t extra_msg
470470
= let aux () : T.Tac (typing g e eff t)
471471
= let fg = elab_env g in
472472
let topt, issues =
@@ -476,11 +476,15 @@ let core_check_term g e eff t
476476
fg e eff t) in
477477
match topt with
478478
| None ->
479-
fail_doc_with_subissues g (Some <| RU.range_of_term e) issues (ill_typed_term e (Some t) None)
479+
fail_doc_with_subissues g (Some <| RU.range_of_term e) issues (extra_msg () @ ill_typed_term e (Some t) None)
480480
| Some tok -> E (RT.T_Token _ _ _ (FStar.Squash.return_squash tok))
481481
in
482482
RU.record_stats "Pulse.core_check_term" aux
483483

484+
485+
let core_check_term g e eff t
486+
= core_check_term' g e eff t fun _ -> []
487+
484488
let core_check_term_at_type g e t
485489
= let aux () : T.Tac (eff:T.tot_or_ghost & typing g e eff t)
486490
= let fg = elab_env g in

src/checker/Pulse.Checker.Pure.fsti

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ val core_compute_term_type (g:env) (t:term)
6565
ty:term &
6666
typing g t eff ty)
6767

68+
val core_check_term' (g:env) (e:term) (eff:T.tot_or_ghost) (t:term)
69+
(extra_msg: unit -> T.Tac (list Pprint.document))
70+
: T.Tac (typing g e eff t)
71+
6872
val core_check_term (g:env) (e:term) (eff:T.tot_or_ghost) (t:term)
6973
: T.Tac (typing g e eff t)
7074

test/nolib/ErrCantFindWitness.fst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module ErrCantFindWitness
2+
#lang-pulse
3+
open Pulse.Nolib
4+
5+
[@@expect_failure]
6+
fn foo ()
7+
ensures exists* (x: nat). emp
8+
{}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
* Info at ErrCantFindWitness.fst(8,1-8,1):
2+
- Expected failure:
3+
- Cannot find witness for exists*:
4+
- (exists* (x:Prims.nat). emp)
5+
- Ill-typed term: (*?u56*)_
6+
- Expected a term of type Prims.nat
7+
- Fstarcompiler.FStarC_Tactics_Common.TacticFailure(_)
8+

0 commit comments

Comments
 (0)