Skip to content
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 build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ lazy val compiler = project
}
},
libraryDependencies += parserCombinators(scalaVersion.value),
libraryDependencies += "org.scalameta" %% "parsers" % "4.13.10",
libraryDependencies += "org.scalameta" %% "parsers" % "4.14.2",
run / fork := true,
buildInfoKeys := Seq[BuildInfoKey](scalaVersion),
buildInfoPackage := "play.twirl.compiler",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ object Helper {
val reporter = driver.compile()

if (reporter.hasErrors) {
val error = reporter.allErrors.sortBy(_.pos.point).head
val errorsSortedAll = reporter.allErrors.sortBy(_.pos.point)
val errorsSortedWithoutZeroPos =
errorsSortedAll.filterNot(e => mapper.mapLine(e.pos.line + 1) == 0 && mapper.mapPosition(e.pos.point) == 0)
// We filter out any errors that are mapped to line 0 and column 0, because since Scalameta 4.14.1 it's likely
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// those are very general errors. However, fall back to all errors in case after filtering no errors are left.
val error = (if (errorsSortedWithoutZeroPos.isEmpty) errorsSortedAll else errorsSortedWithoutZeroPos).head
val message = error.msg
val pos = error.pos
throw CompilationError(message.toString, mapper.mapLine(pos.line + 1), mapper.mapPosition(pos.point))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,23 @@ class CompilerSpec extends AnyWordSpec with Matchers {
}

"fail compilation for error.scala.html" in {
val msg = if (BuildInfo.scalaVersion.startsWith("3.")) "Not found: world" else "not found: value world"
val helper = newCompilerHelper
the[CompilationError] thrownBy helper.compile[(() => Html)]("error.scala.html", "html.error") must have(
Symbol("line")(5),
// Symbol("column")(12) TODO: need fix https://github.com/playframework/twirl/issues/571 to back
Symbol("message")(msg),
Symbol("column")(463)
)
}

"fail compilation for errorInTemplateArgs.scala.html" in {
val helper = newCompilerHelper
val msg =
if (BuildInfo.scalaVersion.startsWith("3.")) "':' expected, but ')' found" else "':' expected but ')' found."
the[CompilationError] thrownBy helper
.compile[(() => Html)]("errorInTemplateArgs.scala.html", "html.errorInTemplateArgs") must have(
Symbol("line")(5),
// Symbol("column")(6) TODO: need fix https://github.com/playframework/twirl/issues/571 to back
Symbol("message")(msg),
Symbol("column")(458)
)
}
Expand Down
Loading