lean4-htt/tests/lean/run/idSuggestShort.lean
Robert J. Simmons 3bd1dd633f
feat: identifier suggestions on some autobinding failures (#11621)
This PR causes Lean to search through `@[suggest_for]` annotations on
certain errors that look like unknown identifiers that got incorrectly
autobound. This will correctly identify that a declaration of type
`Maybe String` should be `Option String` instead.

## Example

```
example : Except String Unit := return .ok ()
```

```
Function expected at
  Result
but this term has type
  ?m.1

Note: Expected a function because this term is being applied to the argument
  String

Hint: The identifier `Result` is unknown, and Lean's `autoImplicit` option causes an unknown identifier to be treated as an implicitly bound variable with an unknown type. However, the unknown type cannot be a function, and a function is what Lean expects here. This is often the result of a typo or a missing `import` or `open` statement.

Perhaps you meant `Except` in place of `Result`?
```

The last line is added by this PR.
2025-12-11 21:40:16 +00:00

69 lines
2.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

set_option autoImplicit false
/--
error: Unknown identifier ``
Note: It is not possible to treat `` as an implicitly bound variable here because the `autoImplicit` option is set to `false`.
Hint: Perhaps you meant `Nat` in place of ``:
[apply] `Nat`
-/
#guard_msgs in example : := 3
/--
error: Unknown identifier `Result`
Note: It is not possible to treat `Result` as an implicitly bound variable here because the `autoImplicit` option is set to `false`.
Hint: Perhaps you meant `Except` in place of `Result`:
[apply] `Except`
-/
#guard_msgs in example : Result String Nat := .ok 3
set_option autoImplicit true
-- The suggestion infrastructure doesn't help us here due to autobinding
/--
error: failed to synthesize instance of type class
OfNat 3
numerals are polymorphic in Lean, but the numeral `3` cannot be used in a context where the expected type is
due to the absence of the instance above
Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
-/
#guard_msgs in example : := 3
/--
@ +0:45...62
error: Function expected at
Result
but this term has type
?m.1
Note: Expected a function because this term is being applied to the argument
String
Hint: The identifier `Result` is unknown, and Lean's `autoImplicit` option causes an unknown identifier to be treated as an implicitly bound variable with an unknown type. However, the unknown type cannot be a function, and a function is what Lean expects here. This is often the result of a typo or a missing `import` or `open` statement.
Perhaps you meant `Except` in place of `Result`?
-/
#guard_msgs (positions := true) in example : Result String Nat := .ok 3
/--
@ +0:45...62
error: Function expected at
Either
but this term has type
?m.1
Note: Expected a function because this term is being applied to the argument
String
Hint: The identifier `Either` is unknown, and Lean's `autoImplicit` option causes an unknown identifier to be treated as an implicitly bound variable with an unknown type. However, the unknown type cannot be a function, and a function is what Lean expects here. This is often the result of a typo or a missing `import` or `open` statement.
Perhaps you meant one of these in place of `Either`:
• `Sum`
• `Except`
-/
#guard_msgs (positions := true) in example : Either String Nat := .ok 3