Configurable warnings, warning suppression

We’re hoping to land the following PR in time for 2.13.2: https://github.com/scala/scala/pull/8373

The starting point was @ghik’s immensely useful “silencer” plugin. We’re very grateful to Roman for pioneering this.

Feedback welcome.

8 Likes

Note that if you want to actually try it out, you can:

resolvers += "pr" at
  "https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots/"
scalaVersion := "2.13.2-bin-59cf05f-SNAPSHOT"

At least, that’s the SHA of the PR’s HEAD at the moment. (There might be newer commits by the time you read this.)

3 Likes

Seems to work on my machine, where

scala --scala-version 2.13.2-bin-59cf05f-SNAPSHOT -e "def t = { 0; 1 }"
warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses
def t = { 0; 1 }
          ^

whilst

scala --scala-version 2.13.2-bin-59cf05f-SNAPSHOT -e "def t = { 0: @scala.annotation.silent; 1 }"

raises no warning. I updated SO Is there an equivalent to SuppressWarnings in Scala?

5 Likes

(Note that Mario is using https://github.com/dwijnand/scala-runners ; that’s what makes scala --scala-version work.)

7 Likes

The PR is now merged, but there is still time for further testing and feedback before the 2.13.2 release.

2 Likes

Just a quick correction of my post as silent was renamed to nowarn in the merged PR.

Lukas has added @nowarn to scala-collection-compat (https://github.com/scala/scala-collection-compat/pull/312) so that people who cross-compile will still be able to use the annotation. (It just won’t actually do anything on 2.11 or 2.12.)

3 Likes

Is it too late for @unwarn and -Xdewarnify?

1 Like

I’m not sure if it’s ever late enough for that.

1 Like

For cross-building,

(As an aside, we’re in the process of renaming scala-collection-compat to scala-library-compat for its next release, since we’ve broadened the project’s scope to include other things besides just collections.)

2 Likes

Hi,

This is a re-post of a questions I asked on scala users.

I’m using the presentation compiler for a hobby project. Up until 2.13.1 I could collect compiler errors and warnings by passing a StoreReporter to the nsc.interactive.Global constructor. This stopped working for warnings with 2.13.2. I suspect this is due to the change introduced by the PR discussed in this thread.

Do you have any advice on how to extract warnings from the presentation compiler after 2.13.2?

Apologies if I’m missing something obvious.

Many thanks,
Christoph

Incidentally what was the reason for not using @SuppressWarning – isn’t that built into Java?

see https://github.com/scala/scala/pull/8373#issuecomment-594458849 (and, Roman concurred at https://github.com/ghik/silencer/pull/41)

Warnings are buffered because you might want to “suppress” them instead of passing them on to the reporter.

The API is global.runReporting.summarizeErrors [sic] where runReporting is currentRun.reporting.

Here is an invocation added to REPL for this purpose.

Perhaps you can use reportSuspendedMessages to end buffering for the run, so that warnings are passed directly to your reporter.

3 Likes

reportSuspendedMessages did the trick - thanks so much!