Skip to content

Commit cdb708f

Browse files
committed
Update docs for compiletime error
1 parent 3142de6 commit cdb708f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

docs/docs/reference/metaprogramming/inline.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,28 @@ The `error` method is used to produce user-defined compile errors during inline
383383
It has the following signature:
384384

385385
```scala
386-
inline def error(inline msg: String, objs: Any*): Nothing
386+
inline def error(inline msg: String): Nothing
387387
```
388388

389389
If an inline expansion results in a call `error(msgStr)` the compiler
390390
produces an error message containing the given `msgStr`.
391391

392+
```scala
393+
inline def fail() = {
394+
error("failed for a reason")
395+
}
396+
fail() // error: failed for a reason
397+
```
398+
399+
or
400+
401+
```scala
402+
inline def fail(p1: => Any) = {
403+
error(code"failed on: $p1")
404+
}
405+
fail(indentity("foo")) // error: failed on: indentity("foo")
406+
```
407+
392408
## Implicit Matches
393409

394410
It is foreseen that many areas of typelevel programming can be done with rewrite

library/src-3.x/scala/compiletime/package.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ package object compiletime {
44

55
erased def erasedValue[T]: T = ???
66

7+
/** The error method is used to produce user-defined compile errors during inline expansion.
8+
* If an inline expansion results in a call error(msgStr) the compiler produces an error message containing the given msgStr.
9+
*
10+
* ```scala
11+
* error("My error message")
12+
* ```
13+
* or
14+
* ```scala
15+
* error(code"My error of this code: ${println("foo")}")
16+
* ```
17+
*/
718
inline def error(inline msg: String): Nothing = ???
819

920
/** Returns the string representations for code passed in the interpolated values

0 commit comments

Comments
 (0)