Skip to content

Commit 862f44a

Browse files
committed
Commas are used to have multiple attributes, so attributes shouldn't contain commas
1 parent 66f0515 commit 862f44a

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

src/Init/Notation.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,14 +638,14 @@ The attribute `@[suggest_for]` on a declaration suggests likely ways in which
638638
someone might **incorrectly** refer to a definition.
639639
640640
* `@[suggest_for String.endPos]` on the definition of `String.rawEndPos` suggests that `"str".endPos` might be correctable to `"str".rawEndPos`.
641-
* `@[suggest_for Either, Result]` on the definition of `Except` suggests that `Either Nat String` might be correctable to `Except Nat String`.
641+
* `@[suggest_for Either Result]` on the definition of `Except` suggests that `Either Nat String` might be correctable to `Except Nat String`.
642642
643643
The namespace of the suggestions is always relative to the root namespace. In the namespace `X.Y`,
644644
adding an annotation `@[suggest_for Z.bar]` to `def Z.foo` will suggest `X.Y.Z.foo` only as a
645645
replacement for `Z.foo`. If your intent is to suggest `X.Y.Z.foo` as a replacement for
646646
`X.Y.Z.bar`, you must instead use the annotation `@[suggest_for X.Y.Z.bar]`.
647647
-/
648-
syntax (name := suggest_for) "suggest_for" ident,+,? : attr
648+
syntax (name := suggest_for) "suggest_for" (ppSpace ident)+ : attr
649649

650650
/--
651651
The `@[coe]` attribute on a function (which should also appear in a

src/Lean/IdentifierSuggestion.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ builtin_initialize identifierSuggestionForAttr : ParametricAttribute (Name × Ar
2222
name := `suggest_for,
2323
descr := "suggest other (incorrect, not-existing) identifiers that someone might use when they actually want this definition",
2424
getParam := fun trueDeclName stx => do
25-
let `(attr| suggest_for $[$altNames],* ) := stx
25+
let `(attr| suggest_for $altNames:ident*) := stx
2626
| throwError "Invalid `[suggest_for]` attribute syntax"
2727
let ns := trueDeclName.getPrefix
2828
return (trueDeclName, altNames.map (·.getId))

tests/lean/run/identifierSuggestions.lean

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
@[suggest_for String.test0, String.test1, String.test2]
1+
@[suggest_for String.test0 String.test1 String.test2]
22
public def String.foo (x: String) := x.length + 1
33

4-
@[suggest_for test1, String.test2]
4+
@[simp, grind, suggest_for test1 String.test2]
55
public def String.bar (x: String) := x.length + 1
66

7-
@[suggest_for String.test1, String.test2]
7+
@[suggest_for String.test1 String.test2, inline]
88
public def String.baz (x: String) := x.length + 1
99

10-
@[suggest_for String.test2]
10+
@[suggest_for String.test2, always_inline]
1111
public def otherFoo (x: String) := x.length + 1
1212

1313
@[suggest_for String.test2]
@@ -96,7 +96,7 @@ attribute [suggest_for Foo.Bar.first] Bar.one
9696
end Foo
9797

9898
namespace Foo.Bar
99-
attribute [suggest_for Foo.Bar.second, Foo.more] Bar.two
99+
attribute [suggest_for Foo.Bar.second Foo.more] Bar.two
100100

101101
@[suggest_for Foo.Bar.toStr]
102102
def toString : Foo.Bar → String
@@ -105,7 +105,7 @@ def toString : Foo.Bar → String
105105
| .three => "three"
106106
end Foo.Bar
107107

108-
attribute [suggest_for Foo.Bar.third, Foo.more] Foo.Bar.three
108+
attribute [suggest_for Foo.Bar.third Foo.more] Foo.Bar.three
109109

110110
@[suggest_for Foo.Bar.toNum]
111111
def Foo.Bar.toNat : Foo.Bar → Nat
@@ -247,3 +247,34 @@ Hint: Perhaps you meant `Bar.one` in place of `Bar.first`:
247247
#guard_msgs in
248248
#eval Bar.first
249249
end Foo
250+
251+
252+
inductive MyBool where | tt | ff
253+
254+
attribute [suggest_for MyBool.true] MyBool.tt
255+
attribute [suggest_for MyBool.false] MyBool.ff
256+
257+
@[suggest_for MyBool.not]
258+
def MyBool.swap : MyBool → MyBool
259+
| tt => ff
260+
| ff => tt
261+
262+
/--
263+
error: Unknown constant `MyBool.true`
264+
265+
Hint: Perhaps you meant `MyBool.tt` in place of `MyBool.true`:
266+
M̵y̵B̵o̵o̵l̵.̵t̵r̵u̵e̵M̲y̲B̲o̲o̲l̲.̲t̲t̲
267+
-/
268+
#guard_msgs in
269+
example := MyBool.true
270+
271+
/--
272+
error: Invalid field `not`: The environment does not contain `MyBool.not`, so it is not possible to project the field `not` from an expression
273+
MyBool.tt
274+
of type `MyBool`
275+
276+
Hint: Perhaps you meant one of these in place of `MyBool.not`:
277+
[apply] `MyBool.swap`: MyBool.tt.swap
278+
-/
279+
#guard_msgs in
280+
example := MyBool.tt.not

0 commit comments

Comments
 (0)