lean4-htt/tests/lean/interactive/4880.lean
Kyle Miller 6c1f8a8a63
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
2024-08-06 22:27:51 +00:00

36 lines
798 B
Text

/-!
# 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