lean4-htt/tests/lean/defInst.lean.expected.out
Robert J. Simmons 429734c02f
feat: suggest deriving an instance when the instance might be derivable (#11346)
This PR modifies the error message for type synthesis failure for the
case where the type class in question is potentially derivable using a
`deriving` command. Also changes the error explanation for type class
instance synthesis failure with an illustration of this pattern.

## Example

```lean4
inductive MyColor where
  | chartreuse | sienna | thistle
def forceColor (oc : Option MyColor) :=
  oc.get!
```

Before this PR, this gives the potentially confusing impression that
Lean may have decided that `MyColor` is _not_ inhabited — people used to
Rust may be especially inclined towards this confusion.
```
failed to synthesize instance of type class
  Inhabited MyColor

Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
```

After this PR, a targeted hint suggests precisely the command that will
fix the issue:
```
error: failed to synthesize instance of type class
  Inhabited MyColor

Hint: Adding the command `deriving instance Inhabited for MyColor` may allow Lean to derive the missing instance.
```
2025-12-01 14:28:15 +00:00

14 lines
402 B
Text

[4, 5, 6]
defInst.lean:8:26-8:32: error(lean.synthInstanceFailed): failed to synthesize instance of type class
BEq Foo
Hint: Adding the command `deriving instance BEq for Foo` may allow Lean to derive the missing instance.
fun x y => sorry : (x y : Foo) → ?m x y
[4, 5, 6]
fun x y => x == y : Foo → Foo → Bool
[("hello", "hello")]
false
true
true
def instMonadM : Monad M :=
ReaderT.instMonad