Skip to content

Commit dde5e9e

Browse files
Fill in the missing docs for compiletime package members
1 parent 412818f commit dde5e9e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

library/src/scala/compiletime/package.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import scala.quoted._
44

55
package object compiletime {
66

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

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

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

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

62+
/** Given a tuple type `(X1, ..., Xn)`, returns a tuple value
63+
* `(constValue[X1], ..., constValue[Xn])`.
64+
*/
4565
inline def constValueTuple[T <: Tuple]: Tuple.Widen[T]=
4666
val res =
4767
inline erasedValue[T] match

0 commit comments

Comments
 (0)