Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatTokensRewrite: check rewritten tokens sorted #3871

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FormatTokensRewrite(

def copySlice(end: Int): Unit = {
val append = end - nextidxToCopy
require(append >= 0) // make sure rewritten tokens are sorted
if (append > 0) {
appended += append
result ++= arr.view.slice(nextidxToCopy, end)
Expand Down Expand Up @@ -308,6 +309,7 @@ object FormatTokensRewrite {
private val claimed = new mutable.HashMap[Int, Int]()
private[FormatTokensRewrite] val tokens =
new mutable.ArrayBuffer[Replacement]()
private[FormatTokensRewrite] var maxClaimed = -1

private[rewrite] def getClaimed(ftIdx: Int): Option[(Int, Replacement)] =
claimed.get(ftIdx) match {
Expand Down Expand Up @@ -366,6 +368,8 @@ object FormatTokensRewrite {
tokens(claimedIdx) = repl
claimedIdx
} else {
require(ftIdx > maxClaimed, s"claiming token at $ftIdx <= $maxClaimed")
maxClaimed = ftIdx
if (preClaimed)
claimed.update(ftIdx, idx)
tokens.append(repl)
Expand Down
Loading