Skip to content

Commit a356207

Browse files
committed
fix: duplicate subexpression info
1 parent 5f23096 commit a356207

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Lean/PrettyPrinter/Parenthesizer.lean

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,17 @@ def term.parenthesizer : CategoryParenthesizer | prec => do
350350
maybeParenthesize `term true wrapParens prec $
351351
parenthesizeCategoryCore `term prec
352352
where
353-
/-- Wraps the term `stx` in parentheses and then copies its `SourceInfo` to the result.
354-
The purpose of this is to copy synthetic delaborator positions from the `stx` node to the parentheses node,
355-
which causes the info view to view both of these nodes as referring to the same expression.
356-
If we did not copy info, the info view would consider the parentheses to belong to the outer term.
353+
/-- Wraps the term `stx` in parentheses and then moves its `SourceInfo` to the result.
354+
The purpose of this is to move synthetic delaborator positions from the `stx` node to the parentheses node,
355+
which causes the info view to view the node with parentheses as referring to the parenthesized expression.
356+
If we did not move info, the info view would consider the parentheses to belong to the outer term.
357357
Note: we do not do `withRef stx` because that causes the "(" and ")" tokens to have source info as well,
358358
causing the info view to highlight each parenthesis as an independent expression. -/
359359
wrapParens (stx : Syntax) : Syntax := Unhygienic.run do
360+
let stxInfo := SourceInfo.fromRef stx
361+
let stx := stx.setInfo .none
360362
let pstx ← `(($(⟨stx⟩)))
361-
return pstx.raw.setInfo (SourceInfo.fromRef stx)
363+
return pstx.raw.setInfo stxInfo
362364

363365
@[builtin_category_parenthesizer tactic]
364366
def tactic.parenthesizer : CategoryParenthesizer | prec => do

0 commit comments

Comments
 (0)