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

Fix Confusing source code position in error message #878

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion mdoc/src/main/scala/mdoc/internal/markdown/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ object Renderer {
case FailSection(instrumented, startLine, startColumn, endLine, endColumn) =>
val input = Input.String(instrumented)
val edit =
TokenEditDistance.fromInputs(doc.sections.map(_.source.pos.input), input)
TokenEditDistance.fromTrees(Seq(section.source.source), input)
val compiled = compiler.fail(edit, input, section.source.pos)
val tpos = new RangePosition(startLine, startColumn, endLine, endColumn)
val pos = tpos.toMeta(section)
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/src/test/scala-3/tests/markdown/FailPositionSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package tests.markdown

import tests.markdown.StringSyntax._
import tests.markdown.Compat

class FailPositionSuite extends BaseMarkdownSuite {

check(
"position",
"""|```scala mdoc
|extension (x: Int)
| def ===(y: Int) = x == y
|```
|
|```scala mdoc:fail
|1 === ""
|```
|
|```scala mdoc:silent
| 1 === 1
|```
""".stripMargin,
"""|```scala
|extension (x: Int)
| def ===(y: Int) = x == y
|```
|
|```scala
|1 === ""
|// error:
|// Found: ("" : String)
|// Required: Int
|// 1 === ""
|// ^^
|```
|
|```scala
| 1 === 1
|```
""".stripMargin
)

}
22 changes: 12 additions & 10 deletions tests/unit/src/test/scala/tests/markdown/FailSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -381,46 +381,48 @@ class FailSuite extends BaseMarkdownSuite {
"two-errors",
"""
|```scala mdoc:fail
|val nope = "foo" * "goo"
|val one = "foo" * "goo"
|```
|
|```scala mdoc:fail
|val bad = "moo" * "loo"
|val two = "moo" * "loo"
|```
""".stripMargin,
"""|```scala
|val nope = "foo" * "goo"
|val one = "foo" * "goo"
|// error: type mismatch;
|// found : String("goo")
|// required: Int
|// val one = "foo" * "goo"
|// ^^^^^
|```
|
|```scala
|val bad = "moo" * "loo"
|val two = "moo" * "loo"
|// error: type mismatch;
|// found : String("loo")
|// required: Int
|// val bad = "moo" * "loo"
|// val two = "moo" * "loo"
|// ^^^^^
|```
|""".stripMargin,
compat = Map(
Compat.Scala3 ->
"""|```scala
|val nope = "foo" * "goo"
|val one = "foo" * "goo"
|// error:
|// Found: ("goo" : String)
|// Required: Int
|// val nope = "foo" * "goo"
|// ^^^^^
|// val one = "foo" * "goo"
|// ^^^^^
|```
|
|```scala
|val bad = "moo" * "loo"
|val two = "moo" * "loo"
|// error:
|// Found: ("loo" : String)
|// Required: Int
|// val bad = "moo" * "loo"
|// val two = "moo" * "loo"
|// ^^^^^
|```
|""".stripMargin
Expand Down