Skip to content

Commit 93528af

Browse files
committed
docs: add in a note about elidable not being supported in Scala 3
This is a follow-up of the comment in #15766 (comment) to try and make it clear to Scala 3 users that while this API exists and is visible in Scala 3, it's not supported by the actual compiler. Therefore it's recommended to instead use the `inline if` alternative. This just adds a note to the Scaladoc to that effect. refs: #15766
1 parent e932f9c commit 93528af

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

library/src/scala/annotation/elidable.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ package scala.annotation
7575
* (O: C).f() // elided if compiled with `-Xelide-below 1`
7676
* }
7777
* }}}
78+
*
79+
* Note for Scala 3 users:
80+
* If you're using Scala 3, the annotation exists since Scala 3 uses the Scala 2
81+
* standard library, but it's unsupported by the Scala 3 compiler. Instead, to
82+
* achieve the same result you'd want to utilize the `inline if` feature to
83+
* introduce behavior that makes a method de facto elided at compile-time.
84+
* {{{
85+
* type LogLevel = Int
86+
*
87+
* object LogLevel:
88+
* inline val Info = 0
89+
* inline val Warn = 1
90+
* inline val Debug = 2
91+
*
92+
* inline val appLogLevel = LogLevel.Warn
93+
*
94+
* inline def log(msg: String, inline level: LogLevel): Unit =
95+
* inline if (level <= appLogLevel) then println(msg)
96+
*
97+
* log("Warn log", LogLevel.Warn)
98+
*
99+
* log("Debug log", LogLevel. Debug)
100+
* }}}
78101
*/
79102
final class elidable(final val level: Int) extends scala.annotation.ConstantAnnotation
80103

0 commit comments

Comments
 (0)