8000 Generate better error messages · CJavaScala/each@0d361bc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d361bc

Browse files
committed
Generate better error messages
1 parent de501d5 commit 0d361bc

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main/scala/com/thoughtworks/each/Monadic.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,18 @@ object Monadic {
131131
val eachMethodSymbol = expectedEachOpsType.member(TermName("each"))
132132

133133
override val eachExtractor: PartialFunction[Tree, Tree] = {
134-
case eachMethodTree@Select(eachOpsTree, _)
135-
if eachMethodTree.symbol == eachMethodSymbol &&
136-
appliedType(eachOpsTree.tpe.typeArgs(0), List(eachMethodTree.tpe)) <:< appliedType(fType, List(eachMethodTree.tpe)) => {
134+
case eachMethodTree@Select(eachOpsTree, _) if eachMethodTree.symbol == eachMethodSymbol => {
135+
val actualFType = eachOpsTree.tpe.typeArgs(0)
136+
val resultType = eachMethodTree.tpe
137+
val expectedType = appliedType(fType, List(resultType))
138+
val actualType = appliedType(actualFType, List(resultType))
139+
if (!(actualType <:< expectedType)) {
140+
c.error(
141+
eachOpsTree.pos,
142+
raw"""type mismatch;
143+
found : ${show(actualType)}
144+
required: ${show(expectedType)}""")
145+
}
137146
Select(eachOpsTree, TermName("underlying"))
138147
}
139148
}

0 commit comments

Comments
 (0)
0