From dde5e9e9070aab31a745ad11b51e21585a6115ca Mon Sep 17 00:00:00 2001 From: Anatolii Kmetiuk Date: Thu, 25 Jun 2020 12:19:27 +0200 Subject: [PATCH] Fill in the missing docs for `compiletime` package members --- library/src/scala/compiletime/package.scala | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/library/src/scala/compiletime/package.scala b/library/src/scala/compiletime/package.scala index 133e4ca9c1ec..39cd810d30ac 100644 --- a/library/src/scala/compiletime/package.scala +++ b/library/src/scala/compiletime/package.scala @@ -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. @@ -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