-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Compiler version
Scala 3.1.x
Minimized code
import scala.annotation.implicitNotFound
@implicitNotFound("Could not find an implicit C[${T}, ${U}]")
class C[T, U]
class K[A] {
def m[B](implicit c: C[List[A], B]) = 0
def n[B](implicit @implicitNotFound("Specific message for C of list of ${A} and ${B}") c: C[List[A], B]) = 1
}
object Test {
val k = new K[Int]
k.m[String]
k.n[String]
}Output
-- Error: ----------------------------------------------------------------------
3 | k.m[String]
| ^
| Could not find an implicit C[List[Int], String]
-- Error: ----------------------------------------------------------------------
4 | k.n[String]
| ^
| Specific message for C of list of Int and String
2 errors foundExpectation
@givenIntanceNotFound("Could not find an implicit C[${T}, ${U}]")
class C[T, U]
class K[A] {
def m[B](using c: C[List[A], B]) = 0
}
object Test {
val k = new K[Int]
k.m[String]
}given:
-- Error: ----------------------------------------------------------------------
3 | k.m[String]
| ^
| Could not find a given instance of C[List[Int], String] in scope
If I remove the @implicitNotFound line , it gives:
[error] -- Error: C:\Users\hepin\IdeaProjects\leetCode\src\main\scala\test\NotFoundImplicit.scala:21:15
[error] 21 | k.m[String]
[error] | ^
[error] |no given instance of type test.NotFoundImplicit.C[List[Int], String] was found for parameter c of method m in class K
So I think we would introduce a new annotation scala.annotation.givenIntanceNotFound?
bjornregnell and julienrf
Metadata
Metadata
Assignees
Labels
No labels
