This PR makes cdot function expansion take hygiene information into account, fixing "parenthesis capturing" errors that can make erroneous cdots trigger cdot expansion in conjunction with macros. For example, given ```lean macro "baz% " t:term : term => `(1 + ($t)) ``` it used to be that `baz% ·` would expand to `1 + fun x => x`, but now the parentheses in `($t)` do not capture the cdot. We also fix an oversight where cdot function expansion ignored the fact that type ascriptions and tuples were supposed to delimit expansion, and also now the quotation prechecker ignores the identifier in `hygieneInfo`. (#9491 added the hygiene information to the parenthesis and cdot syntaxes.) This fixes a bug discovered by [Google DeepMind](https://storage.googleapis.com/deepmind-media/DeepMind.com/Blog/imo-2024-solutions/P1/index.html), which made use of `useλy . x=>y.rec λS p=>?_`. The `use` tactic from Mathlib wrapped the provided term in a type ascription, and so this was equivalent to `use fun x => λy x x=>y.rec λS p=>?_`. (Note that cdot function expansion is not able to take into account *where* the cdots are located, and it is syntactically valid to insert an identifier into the binder list like this. If we ever want to address this in the future, we could have cdots expand into a special term that wraps an identifier that evaluates to a local, but which would cause errors in other contexts.) Design note: we put the `hygieneInfo` on the open parenthesis rather than at the end, since that way the hygiene information is available even when there are parsing errors. This is important since we rely on being able to elaborate partial syntax to get elab info (e.g. in `(a.` to get completion info). Note that syntax matchers check that the `hygieneInfo` is actually present, so such partial syntax would not be matched.
24 lines
602 B
Text
24 lines
602 B
Text
notation "unitTest " x => Prod.mk x ()
|
||
|
||
#check unitTest 42
|
||
|
||
notation "parenthesisTest " x => Nat.sub (x)
|
||
#check parenthesisTest 12
|
||
|
||
def Set (α : Type u) := α → Prop
|
||
def setOf {α : Type} (p : α → Prop) : Set α := p
|
||
notation "{ " x " | " p " }" => setOf (fun x => p)
|
||
|
||
#check { (x : Nat) | x ≤ 1 }
|
||
|
||
notation "cdotTest " "(" x ", " y ")" => Prod.map (· + 1) (1 + ·) (x, y)
|
||
|
||
#check cdotTest (13, 12)
|
||
|
||
notation "tupleFunctionTest " "(" x ", " y ")"=> Prod.map (Nat.add 1) (Nat.add 2) (x, y)
|
||
|
||
#check tupleFunctionTest (15, 12)
|
||
|
||
notation "doubleRhsTest " x => Prod.mk x x
|
||
|
||
#check doubleRhsTest 12
|