Skip to content

Commit

Permalink
Rework compile time error message for scala 3
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.
  • Loading branch information
jodersky committed Nov 2, 2024
1 parent e7fcba1 commit bdffffe
Show file tree
Hide file tree
Showing 3 changed files with 15 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
11 changes: 11 additions & 0 deletions cask/test/src/test/cask/FailureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,16 @@ object FailureTests extends TestSuite {
""").msg ==>
"You can only apply one Endpoint annotation to a function, not 2 in cask.endpoints.get, cask.endpoints.get"
}

"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 bdffffe

Please sign in to comment.