This symbol cast to a free term symbol.
ScalaReflectionException
if isFreeTerm
is false.
This symbol cast to a free type symbol.
ScalaReflectionException
if isFreeType
is false.
Creates an importer that moves reflection artifacts between universes.
If this symbol is a skolem, its corresponding type parameter, otherwise the symbol itself.
To quote Martin Odersky, skolems are synthetic type "constants" that are copies of existentially bound or universally bound type variables. E.g. if one is inside the right-hand side of a method:
def foo[T](x: T) = ... foo[List[T]]....
the skolem named T
refers to the unknown type instance of T
when foo
is called. It needs to be different from the type parameter because in a recursive call as in the foo[List[T]]
above the type parameter gets substituted with List[T]
, but the type skolem stays what it is.
The other form of skolem is an existential skolem. Say one has a function
def bar(xs: List[T] forSome { type T }) = xs.head
then each occurrence of xs
on the right will have type List[T']
where T'
is a fresh copy of T
.
A creator for existential types. This generates:
tpe1 where { tparams }
where tpe1
is the result of extrapolating tpe
with regard to tparams
. Extrapolating means that type variables in tparams
occurring in covariant positions are replaced by upper bounds, (minus any SingletonClass markers), type variables in tparams
occurring in contravariant positions are replaced by upper bounds, provided the resulting type is legal with regard to stability, and does not contain any type variable in tparams
.
The abstraction drops all type parameters that are not directly or indirectly referenced by type tpe1
. If there are no remaining type parameters, simply returns result type tpe
.
Forces all outstanding completers associated with this symbol. After this call returns, the symbol becomes immutable and thread-safe.
A creator for intersection type where intersections of a single type are replaced by the type itself, and repeated parent classes are merged.
!!! Repeated parent classes are not merged - is this a bug in the comment or in the code?
A creator for type parameterizations that strips empty type parameter lists. Use this factory method to indicate the type has kind * (it's a polymorphic value) until we start tracking explicit kinds equivalent to typeFun (except that the latter requires tparams nonEmpty).
Convert a scala.reflect.Manifest to a scala.reflect.api.TypeTags#TypeTag.
Compiler usually generates these conversions automatically, when a manifest for a type T
is in scope, and an implicit of type TypeTag[T]
is requested, but this method can also be called manually. For example:
manifestToTypeTag(scala.reflect.runtime.currentMirror, implicitly[Manifest[String]])
Convert a scala.reflect.api.TypeTags#TypeTag to a scala.reflect.Manifest.
Compiler usually generates these conversions automatically, when a type tag for a type T
is in scope, and an implicit of type Manifest[T]
is requested, but this method can also be called manually. For example:
typeTagToManifest(scala.reflect.runtime.currentMirror, implicitly[TypeTag[String]])
© 2002-2019 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://www.scala-lang.org/api/2.13.0/scala-reflect/scala/reflect/api/Internals$InternalApi.html
Reflection API exhibits a tension inherent to experimental things: on the one hand we want it to grow into a beautiful and robust API, but on the other hand we have to deal with immaturity of underlying mechanisms by providing not very pretty solutions to enable important use cases.
In Scala 2.10, which was our first stab at reflection API, we didn't have a systematic approach to dealing with this tension, sometimes exposing too much of internals (e.g. Symbol.deSkolemize) and sometimes exposing too little (e.g. there's still no facility to change owners, to do typing transformations, etc). This resulted in certain confusion with some internal APIs living among public ones, scaring the newcomers, and some internal APIs only available via casting, which requires intimate knowledge of the compiler and breaks compatibility guarantees.
This led to creation of the
internal
API module for the reflection API, which provides advanced APIs necessary for macros that push boundaries of the state of the art, clearly demarcating them from the more or less straightforward rest and providing compatibility guarantees on par with the rest of the reflection API (full compatibility within minor releases, best effort towards backward compatibility within major releases, clear replacement path in case of rare incompatible changes in major releases).The
internal
module itself (the value that implements InternalApi) isn't defined here, in scala.reflect.api.Universe, but is provided on per-implementation basis. Runtime API endpoint (scala.reflect.runtime.universe) providesuniverse.compat: InternalApi
, whereas compile-time API endpoints (instances of scala.reflect.macros.Context) providec.compat: ContextInternalApi
, which extendsInternalApi
with additional universe-specific and context-specific functionality.