scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.83k stars 1.05k forks source link

Add origin filter to WConf, DeprecationWarning #21404

Closed som-snytt closed 1 month ago

som-snytt commented 1 month ago

The origin parameter to deprecationWarning is optional; the parameter to DeprecationWarning is not.

The origin of a deprecation is simply the deprecated symbol. The full name is matched by the regex specified by -Wconf.

The other important use case is the origin of an unused element, in particular, the selector which causes an "unused import" warning. That use case will be supported in a follow-up PR, and should work as in Scala 2.

Fixes #17538

lrytz commented 1 month ago

We should add documentation here https://github.com/scala/scala3/blob/3.5.0/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala#L251

(After running sbt:scala3> buildQuick, why does bin/scalaQ -Wconf:help only show "-Wconf Configure compiler warnings." and nothing else...?)

Also here https://github.com/scala/scala3/blob/3.5.0/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala#L227

Looks good otherwise!

som-snytt commented 1 month ago

Also the summary counts 4

there were 4 deprecation warnings; re-run with -deprecation for details
1 warning found

but under -deprecation

➜  dotty git:(issue/17538-wconf-origin) ✗ ~/projects/dotty/bin/scalacQ -d /tmp/sandbox -deprecation tests/warn/deprecated-origin.scala
-- Deprecation Warning: tests/warn/deprecated-origin.scala:12:18 ---------------
12 |  class D extends C // nowarn - C$ pattern avoids matching Crude
   |                  ^
   |                 class C in package p is deprecated since 1.0: Old style
-- Deprecation Warning: tests/warn/deprecated-origin.scala:13:20 ---------------
13 |  class Oil extends Crude // warn
   |                    ^^^^^
   |             class Crude in package p is deprecated since 1.0: Bad style
2 warnings found
som-snytt commented 1 month ago

It has taken me more than a few minutes on -Wconf:help, which works on 3.5.0. (This week I upgraded WSL to Ubuntu 24, so among my updated mechanisms is cs, which gave me 3.5.0.) Obviously, it's unpleasant that there is no test; there are a couple of major changes this year. This is what switched from using description to availableBlahBlah (which is shortDescription) https://github.com/scala/scala3/commit/f6345c6202b69a4603cb61ca029d60aa2ac80599

➜  dotty git:(issue/17538-wconf-origin) ✗ scalac -version
Scala compiler version 3.5.0 -- Copyright 2002-2024, LAMP/EPFL
➜  dotty git:(issue/17538-wconf-origin) ✗ scalac -Wconf:help
Configure compiler warnings.
Syntax: -Wconf:<filters>:<action>,<filters>:<action>,...
multiple <filters> are combined with &, i.e., <filter>&...&<filter>

<filter>
  - Any message: any

  - Message categories: cat=deprecation, cat=feature, cat=unchecked
som-snytt commented 1 month ago

I didn't add a -Wconf:help test (the output doesn't show up under vulpix) and didn't look at the warning count issue.