Skip to content

Commit 4e2476c

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

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

library/src/scala/compiletime/package.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ package object compiletime {
5050
* @note only `inline` arguments will be displayed as "code".
5151
* Other values may display unintutively.
5252
*/
53-
transparent inline def code (inline args: Any*): String = ???
53+
transparent inline def code (inline args: Any*): String =
54+
// implemented in dotty.tools.dotc.typer.Inliner.Intrinsics
55+
error("`code` was not evaluated by the compiler")
5456

5557
end extension
5658

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

7377
/** Same as `constValue` but returns a `None` if a constant value
7478
* cannot be constructed from the provided type. Otherwise returns
7579
* that value wrapped in `Some`.
7680
*/
77-
inline def constValueOpt[T]: Option[T] = ???
81+
inline def constValueOpt[T]: Option[T] =
82+
// implemented in dotty.tools.dotc.typer.Inliner
83+
error("`constValueOpt` was not evaluated by the compiler")
7884

7985
/** Given a constant, singleton type `T`, convert it to a value
8086
* of the same singleton type. For example: `assert(constValue[1] == 1)`.
8187
*/
82-
inline def constValue[T]: T = ???
88+
inline def constValue[T]: T =
89+
// implemented in dotty.tools.dotc.typer.Inliner
90+
error("`constValue` was not evaluated by the compiler")
8391

8492
/** Given a tuple type `(X1, ..., Xn)`, returns a tuple value
8593
* `(constValue[X1], ..., constValue[Xn])`.
@@ -106,8 +114,8 @@ package object compiletime {
106114
*
107115
* the returned value would be `2`.
108116
*/
109-
transparent inline def summonFrom[T](f: Nothing => T): T = ???
110-
117+
transparent inline def summonFrom[T](f: Nothing => T): T =
118+
error("`summonFrom` was not evaluated by the compiler")
111119

112120
/** Summon a given value of type `T`. Usually, the argument is not passed explicitly.
113121
* 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)