Question

In the Scala reflection guide is written the following:

As with Manifests, one can in effect request that the compiler generate a TypeTag. This is done by simply specifying an implicit evidence parameter of type TypeTag[T]. If the compiler fails to find a matching implicit value during implicit search, it will automatically generate a TypeTag[T].

This StackOverflow answer beautifully explains the concept of "implicit evidence". However, it is still not completely clear to me what it means that the compiler will generate a TypeTag[T].

  • Does this mean that this is a special case of "implicit evidence" search? I.e. the class TypeTag[T] is handled in a special way when the compiler does implicit search ? I tried to look for implicit parameter values in the Scala reflection APIs but I did not find any which provides a TypeTag[T], so I assume the TypeTag[T] implicit parameter is coming from inside the compiler (as the documentation says). So the classname TypeTag[T] is hardcoded into the compiler's source. Is this assumption correct ?

  • Is the automatic generation of implicit values documented somewhere? In other words, is there a documentation somewhere which lists all the automatically generated implicit evidences ? I did not find TypeTag[T] in the Scala language specification (version 2.9). The closest concept there to TypeTag[T] is Manifest which are automatically generated implicit parameters. Are Manifests the only automatically generated implicit value parameters in Scala 2.9 ?

Was it helpful?

Solution

Yes, TypeTags and WeakTypeTags are treated specially by implicit search. Now that implicit macros actually work, we plan to remove this hardcode, but that remains to be implemented.

So far there's no documentation for automatic generation of implicit values apart from source code, which says that only type tags and manifests are currently generated: https://github.com/scala/scala/blob/38ee986bcad30a8835e8f197112afb5cce2b76c5/src/compiler/scala/tools/nsc/typechecker/Implicits.scala#L1288

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top