scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

scalac: bad option '-Xelide-below' was ignored

Open sabenuse opened this issue 3 years ago • 4 comments

3.1.2

the Compile opton -Xelide-below have removed?

sabenuse avatar Jul 27 '22 08:07 sabenuse

It's not present in Scala 3: https://docs.scala-lang.org/scala3/guides/migration/options-lookup.html

Florian3k avatar Jul 27 '22 08:07 Florian3k

In general, you should be able to achieve similar behavior with inline. What do you want to do?

szymon-rd avatar Jul 27 '22 11:07 szymon-rd

how can i add it ?

sabenuse avatar Jul 27 '22 12:07 sabenuse

@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)

szymon-rd avatar Aug 03 '22 12:08 szymon-rd

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.

b-studios avatar Dec 07 '22 11:12 b-studios

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.

tpunder avatar Apr 01 '23 00:04 tpunder

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

SethTisue avatar Apr 01 '23 06:04 SethTisue

Is the removal of compiler option intentional? Or can someone in theory support this option via PR?

liontiger23 avatar Jun 06 '23 08:06 liontiger23

@liontiger23 see https://github.com/scala/scala/pull/10408 for amended doc. That is, there are better mechanisms.

som-snytt avatar Jun 06 '23 09:06 som-snytt

@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?

liontiger23 avatar Jun 06 '23 09:06 liontiger23

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.

som-snytt avatar Jun 06 '23 09:06 som-snytt

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.

liontiger23 avatar Jun 06 '23 10:06 liontiger23

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.

som-snytt avatar Jun 06 '23 15:06 som-snytt