Skip to content

Commit 3200adf

Browse files
authored
Rework compile time error message for scala 3 (#145)
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.
1 parent d823a8a commit 3200adf

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

build.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import de.tobiasroeser.mill.vcs.version.VcsVersion
1111

1212
val scala213 = "2.13.10"
1313
val scala212 = "2.12.17"
14-
val scala3 = "3.2.2"
14+
val scala3 = "3.3.4"
1515
val scalaJS = "1.13.0"
1616
val communityBuildDottyVersion = sys.props.get("dottyVersion").toList
1717

cask/src-3/cask/router/Macros.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ object Macros {
163163
case iss: ImplicitSearchSuccess =>
164164
iss.tree.asExpr
165165
case isf: ImplicitSearchFailure =>
166-
report.error(s"can't convert ${rtp.typeSymbol.fullName} to a response", method.pos.get)
166+
def prettyPos(pos: Position) =
167+
s"${pos.sourceFile}:${pos.startLine + 1}:${pos.startColumn + 1}"
168+
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)
167169
'{???}
168170
}
169171

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package test.cask
2+
3+
import cask.model.Request
4+
import utest._
5+
6+
object FailureTests3 extends TestSuite {
7+
val tests = Tests{
8+
"returnType" - {
9+
utest.compileError("""
10+
object Routes extends cask.MainRoutes{
11+
@cask.get("/foo")
12+
def hello(world: String) = (1, 1)
13+
initialize()
14+
}
15+
""").msg ==>
16+
"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]"
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)