Adds a mechanism where when an autoparam tactic fails to synthesize a parameter, the associated parameter name or field name for the autoparam is reported in an error. Examples: ```text could not synthesize default value for parameter 'h' using tactics could not synthesize default value for field 'inv' of 'S' using tactics ``` Notes: * Autoparams now run their tactics without any error recovery or error-to-sorry enabled. This enables catching the error and reporting the contextual information. This is justified on the grounds that autoparams are not interactive. * Autoparams for applications now cleanup the autoParam annotation, bringing it in line with autoparams for structure fields. * This preserves the old behavior that autoparams leave terminfo, but we will revisit this after some imminent improvements to the unused variable linter. Closes #2950
48 lines
906 B
Text
48 lines
906 B
Text
/-!
|
|
# Testing the autoparam feature
|
|
-/
|
|
|
|
def f (x y : Nat) (h : x = y := by assumption) : Nat :=
|
|
x + x
|
|
|
|
def g (x y z : Nat) (h : x = y) : Nat :=
|
|
f x y
|
|
|
|
def f2 (x y : Nat) (h : x = y := by exact rfl) : Nat :=
|
|
x + x
|
|
|
|
def f3 (x y : Nat) (h : x = y := by exact Eq.refl x) : Nat :=
|
|
x + x
|
|
|
|
#check fun x => f2 x x
|
|
#check fun x => f3 x x
|
|
|
|
/--
|
|
error: could not synthesize default value for parameter 'h' using tactics
|
|
---
|
|
error: tactic 'assumption' failed
|
|
⊢ 1 = 2
|
|
-/
|
|
#guard_msgs in example := f 1 2
|
|
|
|
/-!
|
|
From #2950, field autoparam should mention which field failed.
|
|
-/
|
|
|
|
structure Foo where
|
|
val : String
|
|
len : Nat := val.length
|
|
inv : val.length = len := by next => decide
|
|
|
|
/--
|
|
error: could not synthesize default value for field 'inv' of 'Foo' using tactics
|
|
---
|
|
error: tactic 'decide' proved that the proposition
|
|
"abc".length = 5
|
|
is false
|
|
-/
|
|
#guard_msgs in
|
|
def test2 : Foo := {
|
|
val := "abc"
|
|
len := 5
|
|
}
|