-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure autoparam errors have correct positions (#4926)
Autoparam tactic scripts have no source positions, which until recently made it so that any errors or messages would be logged at the current ref, which was the application or structure instance being elaborated. However, with the new incrementality features the ref is now carefully managed to avoid leakage of outside data. This inhibits the elaborator's ref from being used for the tactic's ref, causing messages to be placed at the beginning of the file rather than on the syntax that triggered the autoparam. To fix this, now the elaborators insert the ref's source position everywhere into the autoparam tactic script. If in the future messages for synthetic tactics appear at the tops of files in other contexts, we should consider an approach where `Lean.Elab.Term.withReuseContext` uses something like `replaceRef` to set the ref while disabling incrementality when the tactic does not contain source position information. Closes #4880
- Loading branch information
Showing
4 changed files
with
87 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/-! | ||
# Ensure autoparam errors are placed at elaboration position | ||
Before, errors were placed at the beginning of the file. | ||
-/ | ||
|
||
|
||
/-! | ||
Testing `infer_instance`, which defers a typeclass problem beyond the tactic script execution. | ||
-/ | ||
class A | ||
|
||
-- For structure instance elaboration ... | ||
structure B where | ||
h1 : A := by infer_instance | ||
|
||
example : B where | ||
--^ collectDiagnostics | ||
|
||
-- ... and for app elaboration. | ||
def baz (_h1 : A := by infer_instance) : Nat := 1 | ||
|
||
example : Nat := baz | ||
--^ collectDiagnostics | ||
|
||
|
||
/-! | ||
Testing a tactic that immediately throws an error, but incrementality resets the ref | ||
from the syntax for the tactic (which would be a `.missing` position for autoparams). | ||
-/ | ||
|
||
structure B' where | ||
h1 : A := by done | ||
|
||
example : B' where | ||
--^ collectDiagnostics |
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,32 @@ | ||
{"version": 1, | ||
"uri": "file:///4880.lean", | ||
"diagnostics": | ||
[{"source": "Lean 4", | ||
"severity": 1, | ||
"range": | ||
{"start": {"line": 16, "character": 12}, | ||
"end": {"line": 16, "character": 17}}, | ||
"message": | ||
"failed to synthesize\n A\nAdditional diagnostic information may be available using the `set_option diagnostics true` command.", | ||
"fullRange": | ||
{"start": {"line": 16, "character": 12}, | ||
"end": {"line": 16, "character": 17}}}, | ||
{"source": "Lean 4", | ||
"severity": 1, | ||
"range": | ||
{"start": {"line": 22, "character": 17}, | ||
"end": {"line": 22, "character": 20}}, | ||
"message": | ||
"failed to synthesize\n A\nAdditional diagnostic information may be available using the `set_option diagnostics true` command.", | ||
"fullRange": | ||
{"start": {"line": 22, "character": 17}, | ||
"end": {"line": 22, "character": 20}}}, | ||
{"source": "Lean 4", | ||
"severity": 1, | ||
"range": | ||
{"start": {"line": 34, "character": 13}, | ||
"end": {"line": 34, "character": 18}}, | ||
"message": "unsolved goals\n⊢ A", | ||
"fullRange": | ||
{"start": {"line": 34, "character": 13}, | ||
"end": {"line": 34, "character": 18}}}]} |