lean4-htt/tests/lean/run/linterCoe.lean
Paul Reichert 9d7d15b276
feat: lint coercions that are deprecated or banned in core (#11511)
This PR implements a linter that warns when a deprecated coercion is
applied. It also warns when the `Option` coercion or the
`Subarray`-to-`Array` coercion is used in `Init` or `Std`. The linter is
currently limited to `Coe` instances; `CoeFun` instances etc. are not
considered.

The linter works by collecting the `Coe` instance declaration names that
are being expanded in `expandCoe?` and storing them in the info tree.
The linter itself then analyzes the info tree and checks for banned or
deprecated coercions.
2025-12-12 15:09:13 +00:00

59 lines
1.4 KiB
Text

module
-- by default, linters are disabled when running tests
set_option linter.all true
structure X
structure Y
@[deprecated "" (since := "")]
instance mycoe : Coe X Y where coe _ := ⟨⟩
/-- warning: This term uses the coercion `optionCoe`, which is banned in Lean's core library. -/
#guard_msgs in
def f : Option String := "hi"
/--
warning: This term uses the coercion `instCoeSubarrayArray`, which is banned in Lean's core library.
-/
#guard_msgs in
def g : Array Nat := #[1, 2, 3][*...*]
/--
warning: This term uses the deprecated coercion `mycoe`.
Note: This linter can be disabled with `set_option linter.deprecatedCoercions false`
-/
#guard_msgs in
def h (foo : X) : Y := foo
/-- -/
notation a " +' " b => a + b
@[deprecated "" (since := "")]
instance : Coe X Int where
coe _ := 0
/--
@ +1:31...32
warning: This term uses the deprecated coercion `instCoeXInt`.
Note: This linter can be disabled with `set_option linter.deprecatedCoercions false`
---
@ +1:36...37
warning: This term uses the deprecated coercion `instCoeXInt`.
Note: This linter can be disabled with `set_option linter.deprecatedCoercions false`
---
@ +1:41...42
warning: This term uses the deprecated coercion `instCoeXInt`.
Note: This linter can be disabled with `set_option linter.deprecatedCoercions false`
-/
#guard_msgs(positions := true) in
example := fun (n m l : X) => (n + (m +' l) : Int)
set_option linter.deprecatedCoercions false
#guard_msgs in
def h' (foo : X) : Y := foo