Skip to content

Commit

Permalink
TreeOps: handle trailing-comma case for owners
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 9, 2024
1 parent 4c79216 commit 7b9b2ba
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ object TreeOps {
var children = rest
var prevChild: Tree = null
var prevLPs = outerPrevLPs
var prevComma: Token = null

@tailrec
def tokenAt(idx: Int): Int = {
Expand All @@ -954,6 +955,7 @@ object TreeOps {
children = rest
nextChildStart = start
}
prevComma = null
tokenAt(nextIdx)
} else {
def excludeRightParen: Boolean = elem match {
Expand All @@ -975,12 +977,19 @@ object TreeOps {
else {
setOwner(tok, prevChild)
setOwner(prevParens.head, prevChild)
if (prevComma != null)
setOwner(prevComma, prevChild)
}
prevLPs -= 1
prevParens = prevParens.tail
prevComma = null
} else if (tok.is[Comma]) {
prevComma = tok
setOwner(tok, elem)
} else {
setOwner(tok, elem)
if (!tok.is[Trivia] && tokStart != tok.end) {
prevComma = null
prevChild = null
if (tok.is[LeftParen]) {
prevLPs += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ val x = (
x => x + 1,
)
>>>
Idempotency violated
val x = (
x => x + 1,
)
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ val x = (
x => x + 1,
)
>>>
Idempotency violated
val x = (
x => x + 1,
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ val x = (
x => x + 1,
)
>>>
Idempotency violated
val x = (x => x + 1)
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ val x = (
x => x + 1,
)
>>>
Idempotency violated
val x = (
x => x + 1
)
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ val x = (
x => x + 1,
)
>>>
Idempotency violated
val x = (
x => x + 1
)
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ val x = (
x => x + 1,
)
>>>
Idempotency violated
val x = (
x => x + 1
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ val x = (
x => x + 1,
)
>>>
Idempotency violated
val x = (x => x + 1)
Original file line number Diff line number Diff line change
Expand Up @@ -379,5 +379,5 @@ val x = (
)
>>>
val x = (
x => x + 1,
)
x => x + 1,
)

0 comments on commit 7b9b2ba

Please sign in to comment.