Skip to content

Commit d0917c5

Browse files
committed
Add comments and better error messages in case of compiler bug
1 parent a8ecfe5 commit d0917c5

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

library/src/scala/compiletime/package.scala

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ package object compiletime {
2828
* ```scala
2929
* error(code"My error of this code: ${println("foo")}")
3030
* ```
31+
* or
32+
* ```scala
33+
* inline def errorOnThisCode(inline x: Any) =
34+
* error(code"My error of this code: $x")
35+
* ```
3136
*/
3237
inline def error(inline msg: String): Nothing = ???
3338

@@ -50,7 +55,9 @@ package object compiletime {
5055
* @note only `inline` arguments will be displayed as "code".
5156
* Other values may display unintutively.
5257
*/
53-
transparent inline def code (inline args: Any*): String = ???
58+
transparent inline def code (inline args: Any*): String =
59+
// implemented in dotty.tools.dotc.typer.Inliner.Intrinsics
60+
error("`code` was not evaluated by the compiler")
5461

5562
end extension
5663

@@ -68,18 +75,24 @@ package object compiletime {
6875
* twice(m) // error: expected a constant value but found: m
6976
* ```
7077
*/
71-
inline def requireConst(inline x: Boolean | Byte | Short | Int | Long | Float | Double | Char | String): Unit = ()
78+
inline def requireConst(inline x: Boolean | Byte | Short | Int | Long | Float | Double | Char | String): Unit =
79+
// implemented in dotty.tools.dotc.typer.Inliner
80+
error("`requireConst` was not evaluated by the compiler")
7281

7382
/** Same as `constValue` but returns a `None` if a constant value
7483
* cannot be constructed from the provided type. Otherwise returns
7584
* that value wrapped in `Some`.
7685
*/
77-
inline def constValueOpt[T]: Option[T] = ???
86+
inline def constValueOpt[T]: Option[T] =
87+
// implemented in dotty.tools.dotc.typer.Inliner
88+
error("`constValueOpt` was not evaluated by the compiler")
7889

7990
/** Given a constant, singleton type `T`, convert it to a value
8091
* of the same singleton type. For example: `assert(constValue[1] == 1)`.
8192
*/
82-
inline def constValue[T]: T = ???
93+
inline def constValue[T]: T =
94+
// implemented in dotty.tools.dotc.typer.Inliner
95+
error("`constValue` was not evaluated by the compiler")
8396

8497
/** Given a tuple type `(X1, ..., Xn)`, returns a tuple value
8598
* `(constValue[X1], ..., constValue[Xn])`.
@@ -106,8 +119,8 @@ package object compiletime {
106119
*
107120
* the returned value would be `2`.
108121
*/
109-
transparent inline def summonFrom[T](f: Nothing => T): T = ???
110-
122+
transparent inline def summonFrom[T](f: Nothing => T): T =
123+
error("`summonFrom` was not evaluated by the compiler")
111124

112125
/** Summon a given value of type `T`. Usually, the argument is not passed explicitly.
113126
* The summoning is delayed until the call has been fully inlined.

library/src/scala/compiletime/testing/package.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package object testing {
1111
* The code should be a sequence of expressions or statements that may appear in a block.
1212
*/
1313
inline def typeChecks(inline code: String): Boolean =
14+
// implemented in package dotty.tools.dotc.typer.Inliner.Intrinsics
1415
error("`typeChecks` was not checked by the compiler")
1516

1617
/** Whether the code type checks in the current context? If not,
@@ -27,5 +28,6 @@ package object testing {
2728
* The code should be a sequence of expressions or statements that may appear in a block.
2829
*/
2930
inline def typeCheckErrors(inline code: String): List[Error] =
31+
// implemented in package dotty.tools.dotc.typer.Inliner.Intrinsics
3032
error("`typeCheckErrors` was not checked by the compiler")
3133
}

0 commit comments

Comments
 (0)