-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make
elabTermEnsuringType
respect errToSorry
when there is a…
… type mismatch (#3633) Floris van Doorn [reported on Zulip](https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/have.20tactic.20error.20recovery/near/425283053) that it is confusing that the `have : T := e` tactic completely fails if the body `e` is not of type `T`. This is in contrast to `have : T := by exact e`, which does not completely fail when `e` is not of type `T`. This ends up being caused by `elabTermEnsuringType` throwing an error when it fails to insert a coercion. Now, it detects this case, and it checks the `errToSorry` flag to decide whether to throw the error or to log the error and insert a `sorry`. This is justified by `elabTermEnsuringType` being a frontend to `elabTerm`, which inserts `sorry` on error. An alternative would be to make `ensureType` respect `errToSorry`, but there exists code that expects being able to catch when `ensureType` fails. Making such code manipulate `errToSorry` seems error prone, and this function is not a main entry point to the term elaborator, unlike `elabTermEnsuringType`.
- Loading branch information
Showing
5 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/-! | ||
# Tests for the `have` tactic. | ||
-/ | ||
|
||
/-! | ||
If the body of a `have` fails to elaborate, the tactic completes with a `sorry` for the proof. | ||
-/ | ||
/-- | ||
error: type mismatch | ||
False.elim | ||
has type | ||
False → ?m.6 : Sort ?u.5 | ||
but is expected to have type | ||
True : Prop | ||
--- | ||
info: h : True | ||
⊢ True | ||
-/ | ||
#guard_msgs in | ||
example : True := by | ||
have h : True := | ||
False.elim | ||
trace_state | ||
assumption |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters