scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

mention wildcard syntax in "-feature -language:_" in compiler options documentation #12737

Open unkarjedy opened 1 year ago

unkarjedy commented 1 year ago

Scala compiler supports wildcard syntax in compiler options: -feature -language:_ (https://youtrack.jetbrains.com/issue/SCL-18670/regression-scala.concurrent.duration.-postfix-operators-all-read#focus=Comments-27-6898157.0-0)

I couldn't find mentioning of it anywhere in docs. Would be nice if you updated the page: https://docs.scala-lang.org/overviews/compiler-options/index.html and mentioned that -language:_ is also supported

som-snytt commented 1 year ago

still to be resolved is _ vs all. I restored -Vprint:all because dotty. I prefer underscore. But not being able to repeat a command line under both compilers is supremely annoying, so it might be necessary to support both in scala 2 because dotty. I don't recall the history of -language offhand.

unkarjedy commented 1 year ago

_ vs all

Whatever it will be, would be good to document it in Scala 3 docs as well

som-snytt commented 1 year ago

I think Scala 3 disallows wildcard adoption of language features. Quick verification for implicit conversions:

➜  snips ~/projects/dotty/bin/scalac -d /tmp -feature -language:_ language-conversions.scala
-- Feature Warning: language-conversions.scala:6:15 --------------------------------------------------------------------
6 |  implicit def cv(a: A): B = new B {}
  |               ^
  |               Definition of implicit conversion method cv should be enabled
  |               by adding the import clause 'import scala.language.implicitConversions'
  |               or by setting the compiler option -language:implicitConversions.
  |               See the Scala docs for value scala.language.implicitConversions for a discussion
  |               why the feature should be explicitly enabled.
1 warning found
➜  snips ~/projects/dotty/bin/scalac -d /tmp -feature -language:all language-conversions.scala
-- Feature Warning: language-conversions.scala:6:15 --------------------------------------------------------------------
6 |  implicit def cv(a: A): B = new B {}
  |               ^
  |               Definition of implicit conversion method cv should be enabled
  |               by adding the import clause 'import scala.language.implicitConversions'
  |               or by setting the compiler option -language:implicitConversions.
  |               See the Scala docs for value scala.language.implicitConversions for a discussion
  |               why the feature should be explicitly enabled.
1 warning found

It's a minor but unnecessary annoyance that the dotty message reads "Scala docs" instead of "Scaladoc", as though to side-step the question of how to spell it.

➜  snips scalac -d /tmp -feature language-conversions.scala
language-conversions.scala:6: warning: implicit conversion method cv should be enabled
by making the implicit value scala.language.implicitConversions visible.
This can be achieved by adding the import clause 'import scala.language.implicitConversions'
or by setting the compiler option -language:implicitConversions.
See the Scaladoc for value scala.language.implicitConversions for a discussion
why the feature should be explicitly enabled.
  implicit def cv(a: A): B = new B {}
               ^
1 warning
SethTisue commented 1 year ago

I wonder if this ought to be deprecated even in Scala 2

unkarjedy commented 1 year ago

still to be resolved is _ vs all. I restored -Vprint:all because dotty. I prefer underscore. But not being able to repeat a command line under both compilers is supremely annoying, so it might be necessary to support both in scala 2 because dotty. I don't recall the history of -language offhand.

_ vs all Whatever it will be, would be good to document it in Scala 3 docs as well

Actually, now I think that "all" should be supported in 2.13 :) It was supported in all previous Scala 2 versions and in Scala 3.

I noticed the inconvenience when implementing some small internal IntelliJ tool to conveniently browse compiler trees and have to add a special case for Scala 2.13;

      //NOTE: adding "-Ystop-before" not to waste time on generating class files, we are only interested in the trees
      val scalacOptionsToPrintTrees = languageLevel match {
        case Some(value) if value.isScala3 =>
          Seq("-Xprint:all", "-Ystop-before:genBCode")
        case Some(ScalaLanguageLevel.Scala_2_13) =>
          Seq("-Xprint:_", "-Ystop-before:jvm") //TODO: Why only Scala 2.13 compiler doesn't recognise "all"?
        case _ =>
          Seq("-Xprint:all", "-Ystop-before:jvm")
      }
som-snytt commented 1 year ago

@unkarjedy -Vprint:all is supported in 2.13.11

Also, the question is why Dotty reverted to all as a special token. (Because they forked it up.)

Also, it's -Vprint.

unkarjedy commented 1 year ago

@som-snytt

-Vprint:all is supported in 2.13.11

Ah indeed, thanks, I used 2.13.10.

Also, it's -Vprint.

From https://docs.scala-lang.org/overviews/compiler-options/index.html I inferred that -Vprint and -Xprint are the same thing (and both actually work)

image
som-snytt commented 1 year ago

Yes, old options will continue to work so long as people keep using them and they can't be dropped.

However, I continue to evangelize. Or let's say, prepare a way in the desert.

New style is -V for verbose output, -W for warnings, for discoverability. Then -X implies a difference in behavior.

unkarjedy commented 1 year ago

Ok, I got it 👍

In order for evangelising to be more productive, IMO it should be supported by changes in the official places:

  1. https://docs.scala-lang.org/overviews/compiler-options/index.html Rewrite -Vprint ARG or -Xprint ARG, -Vprint-pos or -Xprint-pos, etc... with something like -Vprint ARG (or deprecated -Xprint ARG), -Vprint-pos (or deprecated -Xprint-pos) Or something like that. The main thing is to explicitly mention that it's an undesired option.

    image
  2. https://docs.scala-lang.org/scala3/guides/migration/options-new.html Ping Scala 3 guys and ask them to replace these new options with -V alternative and mention that on the site. (should we CC someone here?)

    image

Right now -V alternatives produce compilation errors:

scalac: bad option '-Vprint-diff' was ignored
scalac: bad option '-Vprint-inline' was ignored
  1. Introduce some "soft" compiler warning in newest Scala 2 and Scala 3 compiler versions? Maybe not a "WARNING" but a single output line? At least under some extra linting option? Maybe it's already done?