lean4-htt/tests/lean/run/idSuggestEvery.lean
Robert J. Simmons f88e503f3d
feat: @[suggest_for] annotations for prompting easy-to-miss names (#11554)
This PR adds `@[suggest_for]` annotations to Lean, allowing lean to
provide corrections for `.every` or `.some` methods in place of `.all`
or `.any` methods for most default-imported types (arrays, lists,
strings, substrings, and subarrays, and vectors).

Due to the need for stage0 updates for new annotations, the
`suggest_for` annotation itself was introduced in previous PRs: #11367,
#11529, and #11590.

## Example
```
example := "abc".every (! ·.isWhitespace)
```

Error message:
```
Invalid field `every`: The environment does not contain `String.every`, so it is not possible to project the field `every` from an expression
  "abc"
of type `String`

Hint: Perhaps you meant `String.all` in place of `String.every`:
  .e̵v̵e̵r̵y̵a̲l̲l̲
```

(the hint is added by this PR)

## Additional changes

Adds suggestions that are not currently active but that can be used to
generate autocompletion suggestions in the reference manual:
 - `Either` -> `Except` and `Sum`
 - `Exception` -> `Except`
 - `ℕ` -> `Nat`
 - `Nullable` -> `Option` 
 - `Maybe` -> `Option`
 - `Optional` -> `Option`
 - `Result` -> `Except`
2025-12-10 22:50:45 +00:00

110 lines
3.8 KiB
Text

-- test every/all replacements in default imports
/-
Expected replacements for `Subarray.any` and `Subarray.all` do not work as suggestion annotations
when using generalized field notation: Subarray is an abbreviation and so the underlying `Std.Slice`
type, which does not have a corresponding `.any`/`.all` function.
-/
/--
error: Invalid field `every`: The environment does not contain `Std.Slice.every`, so it is not possible to project the field `every` from an expression
x
of type
Std.Slice (Std.Slice.Internal.SubarrayData Nat)
-/
#guard_msgs in example (x : Subarray Nat) := x.every fun _ => true
#guard_msgs in example (x : Subarray Nat) := x.all fun _ => true
/--
error: Unknown constant `Subarray.every`
Hint: Perhaps you meant `Subarray.all` in place of `Subarray.every`:
[apply] `Subarray.all`
-/
#guard_msgs in example := (@Subarray.every Nat (fun _ => true) ·)
#guard_msgs in example := (@Subarray.all Nat (fun _ => true) ·)
/--
error: Unknown constant `Subarray.some`
Hint: Perhaps you meant `Subarray.any` in place of `Subarray.some`:
[apply] `Subarray.any`
-/
#guard_msgs in example := (@Subarray.some Nat (fun _ => true) ·)
#guard_msgs in example := (@Subarray.any Nat (fun _ => true) ·)
/--
error: Invalid field `every`: The environment does not contain `String.every`, so it is not possible to project the field `every` from an expression
x
of type `String`
Hint: Perhaps you meant `String.all` in place of `String.every`:
.e̵v̵e̵r̵y̵a̲l̲l̲
-/
#guard_msgs in example (x : String) := x.every fun _ => true
#guard_msgs in example (x : String) := x.all fun _ => true
/--
error: Invalid field `some`: The environment does not contain `String.some`, so it is not possible to project the field `some` from an expression
x
of type `String`
Hint: Perhaps you meant `String.contains` in place of `String.some`:
.s̵o̵m̵e̵c̲o̲n̲t̲a̲i̲n̲s̲
-/
#guard_msgs in example (x : String) := x.some fun _ => true
#guard_msgs in example (x : String) := x.contains fun _ => true
/--
error: Invalid field `every`: The environment does not contain `Array.every`, so it is not possible to project the field `every` from an expression
x
of type `Array Nat`
Hint: Perhaps you meant `Array.all` in place of `Array.every`:
.e̵v̵e̵r̵y̵a̲l̲l̲
-/
#guard_msgs in example (x : Array Nat) := x.every fun _ => true
#guard_msgs in example (x : Array Nat) := x.all fun _ => true
/--
error: Invalid field `some`: The environment does not contain `Array.some`, so it is not possible to project the field `some` from an expression
x
of type `Array Nat`
Hint: Perhaps you meant `Array.any` in place of `Array.some`:
.s̵o̵m̵e̵a̲n̲y̲
-/
#guard_msgs in example (x : Array Nat) := x.some fun _ => true
#guard_msgs in example (x : Array Nat) := x.all fun _ => true
/--
error: Invalid field `every`: The environment does not contain `List.every`, so it is not possible to project the field `every` from an expression
x
of type `List Nat`
Hint: Perhaps you meant `List.all` in place of `List.every`:
.e̵v̵e̵r̵y̵a̲l̲l̲
-/
#guard_msgs in example (x : List Nat) := x.every fun _ => true
#guard_msgs in example (x : List Nat) := x.all fun _ => true
/--
error: Invalid field `some`: The environment does not contain `List.some`, so it is not possible to project the field `some` from an expression
x
of type `List Nat`
Hint: Perhaps you meant `List.any` in place of `List.some`:
.s̵o̵m̵e̵a̲n̲y̲
-/
#guard_msgs in example (x : List Nat) := x.some fun _ => true
#guard_msgs in example (x : List Nat) := x.all fun _ => true
/--
@ +1:17...22
error: Invalid field `every`: The environment does not contain `List.every`, so it is not possible to project the field `every` from an expression
[1, 2, 3]
of type `List ?m.10`
Hint: Perhaps you meant `List.all` in place of `List.every`:
.e̵v̵e̵r̵y̵a̲l̲l̲
-/
#guard_msgs (positions := true) in
#check [1, 2, 3].every