Skip to content

Commit

Permalink
Fill in the missing docs for compiletime package members
Browse files Browse the repository at this point in the history
  • Loading branch information
anatoliykmetyuk committed Jun 25, 2020
1 parent 412818f commit dde5e9e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions library/src/scala/compiletime/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import scala.quoted._

package object compiletime {

/** Use this method when you have a type, do not have a value for it but want to
* pattern match on it. For example, given a type `Tup <: Tuple`, one can
* pattern-match on it as follows:
* ```
* erasedValue[Tup] match {
* case _: EmptyTuple => ...
* case _: h *: t => ...
* }
* ```
*/
erased def erasedValue[T]: T = ???

/** The error method is used to produce user-defined compile errors during inline expansion.
Expand Down Expand Up @@ -38,10 +48,20 @@ package object compiletime {
transparent inline def (inline self: StringContext) code (inline args: Any*): String =
${ dotty.internal.CompileTimeMacros.codeExpr('self, 'args) }

/** Same as `constValue` but returns a `None` if a constant value
* cannot be constructed from the provided type. Otherwise returns
* that value wrapped in `Some`.
*/
inline def constValueOpt[T]: Option[T] = ???

/** Given a constant, singleton type `T`, convert it to a value
* of the same singleton type. For example: `assert(constValue[1] == 1)`.
*/
inline def constValue[T]: T = ???

/** Given a tuple type `(X1, ..., Xn)`, returns a tuple value
* `(constValue[X1], ..., constValue[Xn])`.
*/
inline def constValueTuple[T <: Tuple]: Tuple.Widen[T]=
val res =
inline erasedValue[T] match
Expand Down

0 comments on commit dde5e9e

Please sign in to comment.