Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.annotation/implicitNotFound

implicitNotFound

scala.annotation.implicitNotFound

To customize the error message that's emitted when an implicit of typeC[T1,..., TN] cannot be found, annotate the classC with@implicitNotFound. AssumingC has type parametersX1, ..., XN, the error message will be the result of replacing all occurrences of${Xi} in the stringmsg with the string representation of the corresponding type argumentTi. The annotation is effectively inherited by subtypes if they are not annotated.

The annotation can also be attached to implicit parameters. In this case,${Xi} can refer to type parameters in the current scope. The@implicitNotFound message on the parameter takes precedence over the one on the parameter's type.

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]}

The compiler issues the following error messages:

Test.scala:13: error: Could not find an implicit C[List[Int], String] k.m[String]    ^Test.scala:14: error: Specific message for C of list of Int and String k.n[String]    ^

Attributes

Source
implicitNotFound.scala
Graph
Supertypes
classObject
traitMatchable
classAny
Show all
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp