Skip to content

Commit d9ac112

Browse files
authored
Merge pull request #386 from tgodzik/fix-wrong-error-pos
Add -1 for any diagnostics using point() in Scala 3
2 parents 377c36a + c5ae028 commit d9ac112

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

mdoc/src/main/scala-3/mdoc/internal/markdown/MarkdownCompiler.scala

+14-19
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,21 @@ class MarkdownCompiler(
150150

151151
private def toMetaPosition(
152152
edit: TokenEditDistance,
153-
pos: java.util.Optional[SourcePosition]
153+
position: SourcePosition
154154
): Position = {
155-
if (pos.isPresent) {
156-
val position = pos.get
157-
def toOffsetPosition(offset: Int): Position = {
158-
edit.toOriginal(offset) match {
159-
case Left(_) =>
160-
Position.None
161-
case Right(p) =>
162-
p.toUnslicedPosition
163-
}
155+
def toOffsetPosition(offset: Int): Position = {
156+
edit.toOriginal(offset) match {
157+
case Left(_) =>
158+
Position.None
159+
case Right(p) =>
160+
p.toUnslicedPosition
164161
}
165-
(edit.toOriginal(pos.get.start), edit.toOriginal(pos.get.end - 1)) match {
166-
case (Right(start), Right(end)) =>
167-
Position.Range(start.input, start.start, end.end).toUnslicedPosition
168-
case (_, _) =>
169-
toOffsetPosition(pos.get.point)
170-
}
171-
} else {
172-
Position.None
162+
}
163+
(edit.toOriginal(position.start), edit.toOriginal(position.end - 1)) match {
164+
case (Right(start), Right(end)) =>
165+
Position.Range(start.input, start.start, end.end).toUnslicedPosition
166+
case (_, _) =>
167+
toOffsetPosition(position.point - 1)
173168
}
174169
}
175170

@@ -187,7 +182,7 @@ class MarkdownCompiler(
187182
case diagnostic if diagnostic.position.isPresent =>
188183
val pos = diagnostic.position.get
189184
val msg = nullableMessage(diagnostic.message)
190-
val mpos = toMetaPosition(edit,java.util.Optional.of(pos))
185+
val mpos = toMetaPosition(edit, pos)
191186
val actualMessage =
192187
if (mpos == Position.None) {
193188
val line = pos.lineContent

tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala

+17
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,23 @@ class WorksheetSuite extends BaseSuite {
329329
|""".stripMargin
330330
)
331331

332+
checkDiagnostics(
333+
"dotty-ambiguous-implicit".tag(OnlyScala3),
334+
"""|abstract class C:
335+
| val x: Int
336+
|given c1 as C:
337+
| val x = 1
338+
|given c2 as C:
339+
| val x = 2
340+
|def fn(using c: C) = ()
341+
|val xx = fn
342+
|""".stripMargin,
343+
"""|dotty-ambiguous-implicit:8:10: error: ambiguous implicit arguments: both object c1 in class App and object c2 in class App match type App.this.C of parameter c of method fn in class App
344+
|val xx = fn
345+
| ^^
346+
|""".stripMargin
347+
)
348+
332349
checkDecorations(
333350
"dotty-imports".tag(OnlyScala3),
334351
"""|import $dep.`com.lihaoyi:scalatags_2.13:0.9.1`

0 commit comments

Comments
 (0)