This PR adds two validation checks to `addInstance` that provide early feedback for common mistakes in instance declarations: 1. **Non-class instance check**: errors when an instance target type is not a type class. This catches the common mistake of writing `instance` for a plain structure. Previously handled by the `nonClassInstance` linter in Batteries (`Batteries.Tactic.Lint.TypeClass`), this is now checked directly at declaration time. 2. **Impossible argument check**: errors when an instance has arguments that cannot be inferred by instance synthesis. Specifically, it flags arguments that are not instance-implicit and do not appear in any subsequent instance-implicit argument or in the return type. Previously such instances would be silently accepted but could never be synthesised. Supersedes #13237 and #13333.
28 lines
390 B
Text
28 lines
390 B
Text
/-!
|
|
# `instance` creates a theorem if the class is a `Prop`
|
|
|
|
https://github.com/leanprover/lean4/issues/5672
|
|
-/
|
|
|
|
class A : Prop
|
|
|
|
instance a : A where
|
|
|
|
/--
|
|
info: theorem a : A :=
|
|
{ }
|
|
-/
|
|
#guard_msgs in #print a
|
|
|
|
|
|
/-!
|
|
Uses `def` variable inclusion rules
|
|
-/
|
|
section
|
|
variable (x : Nat)
|
|
@[reducible]
|
|
def b : A := by
|
|
cases x <;> exact {}
|
|
/-- info: b (x : Nat) : A -/
|
|
#guard_msgs in #check b
|
|
end
|