File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
docs/docs/reference/metaprogramming
library/src-3.x/scala/compiletime Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -383,12 +383,28 @@ The `error` method is used to produce user-defined compile errors during inline
383383It 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
389389If an inline expansion results in a call ` error(msgStr) ` the compiler
390390produces 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
394410It is foreseen that many areas of typelevel programming can be done with rewrite
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments