lean4-htt/tests/elab/5672.lean
Wojciech Różowski 3fc99eef10
feat: add instance validation checks in addInstance (#13389)
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.
2026-04-16 17:48:16 +00:00

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