This PR removes most cases where an error message explained that it was "probably due to metavariables," giving more explanation and a hint. ## Example ``` def square x := x * x ``` Before: ```lean4 typeclass instance problem is stuck, it is often due to metavariables HMul ?m.9 ?m.9 (?m.3 x) ``` After: ``` typeclass instance problem is stuck HMul ?m.9 ?m.9 (?m.3 x) Note: Lean will not try to resolve this typeclass instance problem because the first and second type arguments to `HMul` are metavariables. These arguments must be fully determined before Lean will try to resolve the typeclass. Hint: Adding type annotations and supplying implicit arguments to functions can give Lean more information for typeclass resolution. For example, if you have a variable `x` that you intend to be a `Nat`, but Lean reports it as having an unresolved type like `?m`, replacing `x` with `(x : Nat)` can get typeclass resolution un-stuck. ``` In addition to providing beginner-and-intermediate-friendly explanation about **why** typeclass instance problems are treated as "stuck" when metavariables appear in output positions, this PR provides potentially-valuable improvement even to expert users: it explains **which of the typeclass arguments are inputs** and therefore need to be fully specified before typeclass resolution will be attempted. This information can be tricky to find otherwise. ## Next steps, but probably after this PR * error explanation * detecting when the syntactic source is a binop and giving a special-cased explanation on the binary operators and their associated typeclasses * detecting when the syntactic source is a function call, inspecting the function call's type somewhat, and replacing the generic "replace `x` with `(x : Nat)` hint with a specialized "replace `foo` with `foo (tyArg := Nat)`" hint
10 lines
837 B
Text
10 lines
837 B
Text
defaultInstance.lean:20:20-20:23: error: failed to synthesize
|
|
Foo Bool (?m x)
|
|
|
|
Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.
|
|
defaultInstance.lean:22:35-22:38: error: typeclass instance problem is stuck
|
|
Foo Bool (?m x)
|
|
|
|
Note: Lean will not try to resolve this typeclass instance problem because the second type argument to `Foo` contains metavariables. This argument must be fully determined before Lean will try to resolve the typeclass.
|
|
|
|
Hint: Adding type annotations and supplying implicit arguments to functions can give Lean more information for typeclass resolution. For example, if you have a variable `x` that you intend to be a `Nat`, but Lean reports it as having an unresolved type like `?m`, replacing `x` with `(x : Nat)` can get typeclass resolution un-stuck.
|