diff --git a/core/shared/src/main/scala/cats/parse/LocationMap.scala b/core/shared/src/main/scala/cats/parse/LocationMap.scala index 27a60066..8a24fef5 100644 --- a/core/shared/src/main/scala/cats/parse/LocationMap.scala +++ b/core/shared/src/main/scala/cats/parse/LocationMap.scala @@ -69,7 +69,7 @@ class LocationMap(val input: String) { */ def toLineCol(offset: Int): Option[(Int, Int)] = if (isValidOffset(offset)) { - val Caret(_, line, col) = toCaretUnsafeImpl(offset) + val Caret(line, col, _) = toCaretUnsafeImpl(offset) Some((line, col)) } else None @@ -81,9 +81,9 @@ class LocationMap(val input: String) { // this is end of line if (offset == 0) Caret.Start else { - val Caret(_, line, col) = toCaretUnsafeImpl(offset - 1) - if (endsWithNewLine) Caret(offset, line + 1, 0) - else Caret(offset, line, col + 1) + val Caret(line, col, _) = toCaretUnsafeImpl(offset - 1) + if (endsWithNewLine) Caret(line = line + 1, col = 0, offset = offset) + else Caret(line = line, col = col + 1, offset = offset) } } else { val idx = Arrays.binarySearch(firstPos, offset) @@ -98,10 +98,10 @@ class LocationMap(val input: String) { // so we are pointing into a line val lineStart = firstPos(line) val col = offset - lineStart - Caret(offset, line, col) + Caret(line = line, col = col, offset = offset) } else { // idx is exactly the right value because offset is beginning of a line - Caret(offset, idx, 0) + Caret(line = idx, col = 0, offset = offset) } } diff --git a/core/shared/src/test/scala/cats/parse/LocationMapTest.scala b/core/shared/src/test/scala/cats/parse/LocationMapTest.scala index 6d5d446e..0bf89de8 100644 --- a/core/shared/src/test/scala/cats/parse/LocationMapTest.scala +++ b/core/shared/src/test/scala/cats/parse/LocationMapTest.scala @@ -226,7 +226,8 @@ class LocationMapTest extends munit.ScalaCheckSuite { val lc = lm.toLineCol(offset) assertEquals(oc, Some(c)) - assertEquals(lc, oc.map { case Caret(_, r, c) => (r, c) }) + assertEquals(lc, oc.map { c => (c.line, c.col) }) + assertEquals(c.offset, offset) } if (other < 0 || s.length < other) {