Skip to content

Commit

Permalink
Rework compile time error message for scala 3 (#145)
Browse files Browse the repository at this point in the history
This includes more information in the error message that is generated
when a route declaration has an invalid return type.

It notably also includes the source position, as discussed in #141.
  • Loading branch information
jodersky authored Nov 3, 2024
1 parent d823a8a commit 3200adf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import de.tobiasroeser.mill.vcs.version.VcsVersion

val scala213 = "2.13.10"
val scala212 = "2.12.17"
val scala3 = "3.2.2"
val scala3 = "3.3.4"
val scalaJS = "1.13.0"
val communityBuildDottyVersion = sys.props.get("dottyVersion").toList

Expand Down
4 changes: 3 additions & 1 deletion cask/src-3/cask/router/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ object Macros {
case iss: ImplicitSearchSuccess =>
iss.tree.asExpr
case isf: ImplicitSearchFailure =>
report.error(s"can't convert ${rtp.typeSymbol.fullName} to a response", method.pos.get)
def prettyPos(pos: Position) =
s"${pos.sourceFile}:${pos.startLine + 1}:${pos.startColumn + 1}"
report.error(s"error in route definition `def ${method.name}` (at ${prettyPos(method.pos.get)}): the method's return type ${rtp.show} cannot be converted to the expected response type ${innerReturnedTpt.show}", method.pos.get)
'{???}
}

Expand Down
19 changes: 19 additions & 0 deletions cask/test/src-3/test/cask/FailureTests3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test.cask

import cask.model.Request
import utest._

object FailureTests3 extends TestSuite {
val tests = Tests{
"returnType" - {
utest.compileError("""
object Routes extends cask.MainRoutes{
@cask.get("/foo")
def hello(world: String) = (1, 1)
initialize()
}
""").msg ==>
"error in route definition `def hello` (at tasty-reflect:4:15): the method's return type scala.Tuple2[scala.Int, scala.Int] cannot be converted to the expected response type cask.model.Response[cask.model.Response.Data]"
}
}
}

0 comments on commit 3200adf

Please sign in to comment.