Open sabenuse opened 2 years ago
It's not present in Scala 3: https://docs.scala-lang.org/scala3/guides/migration/options-lookup.html
In general, you should be able to achieve similar behavior with inline
. What do you want to do?
how can i add it ?
@sabenuse It is a new language feature in Scala 3. If you use the inline if
, then you can introduce a behavior that makes a method de facto elided at compile-time:
type LogLevel = Int
object LogLevel {
inline val Info = 0
inline val Warn = 1
inline val Debug = 2
}
inline val appLogLevel = LogLevel.Warn
inline def log(msg: String, inline level: LogLevel): Unit =
inline if (level <= appLogLevel) then println(msg)
log("Warn log", LogLevel.Warn)
log("Debug log", LogLevel. Debug)
Hey, does anybody know whether it is supposed to be supported in the future? I am surprised to find it in the docs:
https://dotty.epfl.ch/api/scala/annotation/elidable.html
but get the same message as the OP.
Use-case I want to use it for "design by contract". Disabling assertions for production in a compiler flag seems like a reasonable thing to do. Having to develop your own assertions might not scale to code that already uses assertions.
I just ran into this issue while trying to cross-compile Scala 2 and Scala 3 code. I assumed it was supported since @elidable
is still part of the API (https://scala-lang.org/api/3.2.2/scala/annotation/elidable.html) and the code compiles fine using @elidable
.
If it is no longer supported then it would probably be nice to remove it from the API or at least add a big note in the API docs that it is not supported in Scala 3 and that -Xelide-below
is no longer valid.
at least add a big note in the API docs that it is not supported in Scala 3
yes, a PR with that would be welcome over at https://github.com/scala/scala
Is the removal of compiler option intentional? Or can someone in theory support this option via PR?
@liontiger23 see https://github.com/scala/scala/pull/10408 for amended doc. That is, there are better mechanisms.
@liontiger23 see https://github.com/scala/scala/pull/10408 for amended doc. That is, there are better mechanisms.
I understand that it is currently not implemented in the compiler.
My question is whether the contribution that supports this option be accepted? Or maybe there are some problems in practice or in principle with the existence of this functionality?
I believe their intention is not to implement it because there are better mechanisms as described in the scaladoc. I am not the authority; that is what I observe. The problem in practice is maintenance and too many ways to accomplish the same thing.
I am not convinced that it is a better mechanism.
Proposed workaround using inline if
requires source code modification in order to change the eliding behavior, while compile option allowed to change behavior at build time without any source code modification.
For the general case, I would want an easy way to specify "prod" vs "dev" module at build time (to use the right config module).
I think the assert
use case (mentioned above) deserves its own ticket.
They've been migrating tickets to discussions; this one might be a good candidate for that.
(I was a fan of the Scala 2 feature in so far as I fixed some bugs in it.)
Edit: sjrd's reply on discord is uncharacteristically encouraging.
3.1.2
the Compile opton -Xelide-below have removed?