Skip to content

Commit

Permalink
doc(lint/type_classes): add has_coe_to_fun linter (#5546)
Browse files Browse the repository at this point in the history
  • Loading branch information
fpvandoorn committed Jan 1, 2021
1 parent d2bde11 commit fcbaf62
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/logic/basic.lean
Expand Up @@ -85,7 +85,7 @@ theorem coe_sort_coe_trans
Many structures such as bundled morphisms coerce to functions so that you can
transparently apply them to arguments. For example, if `e : α ≃ β` and `a : α`
then you can write `e a` and this is elaborated as `⇑e a`. This type of
coercion is implemented using the `has_coe_to_fun`type class. There is one
coercion is implemented using the `has_coe_to_fun` type class. There is one
important consideration:
If a type coerces to another type which in turn coerces to a function,
Expand Down
4 changes: 3 additions & 1 deletion src/tactic/lint/type_classes.lean
Expand Up @@ -23,6 +23,7 @@ and the appropriate definition of instances:
to `[nonempty α]`
* `decidable_classical` checks propositions for `[decidable_... p]` hypotheses that are not used
in the statement, and could thus be removed by using `classical` in the proof.
* `linter.has_coe_to_fun` checks whether necessary `has_coe_to_fun` instances are declared
-/

open tactic
Expand Down Expand Up @@ -300,6 +301,7 @@ attribute [nolint decidable_classical] dec_em not.decidable_imp_symm

private meta def has_coe_to_fun_linter (d : declaration) : tactic (option string) :=
retrieve $ do
tt ← return d.is_trusted | pure none,
mk_meta_var d.type >>= set_goals ∘ pure,
args ← unfreezing intros,
expr.sort _ ← target | pure none,
Expand All @@ -325,4 +327,4 @@ pure $ format.to_string $
no_errors_found := "has_coe_to_fun is used correctly",
errors_found := "INVALID/MISSING `has_coe_to_fun` instances.
You should add a `has_coe_to_fun` instance for the following types.
See Note function coercions]." }
See Note [function coercion]." }

0 comments on commit fcbaf62

Please sign in to comment.