Closed
Description
Compiler version
3.3.1
Minimized code
import scala.annotation.nowarn
@deprecated("is deprecated", "n/a")
class Thing(val value: Int)
object Main extends App {
@nowarn("msg=is deprecated")
def doo(): Option[Thing] = Some(new Thing(1))
def wop(x: => Option[Thing]) = println(x)
doo().map(t => println(t))
doo().map((t: Thing) => println(t))
doo().map(println)
doo().foreach(println)
for (x <- doo()) println(x)
val thing = new Thing(42)
println(thing)
val something = Some(thing)
wop(something)
}
Output
$ scalac -deprecation warns-too-much.scala
-- Deprecation Warning: warns-too-much.scala:12:23 ---------------------------------------------------------------------
12 | def wop(x: => Option[Thing]) = println(x)
| ^^^^^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: warns-too-much.scala:14:13 ---------------------------------------------------------------------
14 | doo().map(t => println(t))
| ^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: warns-too-much.scala:15:16 ---------------------------------------------------------------------
15 | doo().map((t: Thing) => println(t))
| ^^^^^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: warns-too-much.scala:18:8 ----------------------------------------------------------------------
18 | for (x <- doo()) println(x)
| ^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: warns-too-much.scala:20:11 ---------------------------------------------------------------------
20 | val thing = new Thing(42)
| ^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: warns-too-much.scala:20:18 ---------------------------------------------------------------------
20 | val thing = new Thing(42)
| ^^^^^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: warns-too-much.scala:23:15 ---------------------------------------------------------------------
23 | val something = Some(thing)
| ^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: warns-too-much.scala:23:18 ---------------------------------------------------------------------
23 | val something = Some(thing)
| ^^^^
| class Thing is deprecated since n/a: is deprecated
8 warnings found
Expectation
$ scalac -Xlint warns-too-much.scala
warns-too-much.scala:12: warning: class Thing is deprecated (since n/a): is deprecated
def wop(x: => Option[Thing]) = println(x)
^
warns-too-much.scala:15: warning: class Thing is deprecated (since n/a): is deprecated
doo().map((t: Thing) => println(t))
^
warns-too-much.scala:20: warning: class Thing is deprecated (since n/a): is deprecated
val thing = new Thing(42)
^
3 warnings
Compare f, which does not warn:
➜ cat jdep.java
import java.util.Optional;
@Deprecated
class jdep {
}
class client {
jdep g() {
return new jdep();
}
void f() {
var x = g();
System.out.println(x);
var y = Optional.of(g());
System.out.println(y);
}
}
➜ javac -Xlint:deprecation jdep.java
jdep.java:9: warning: [deprecation] jdep in unnamed package has been deprecated
jdep g() {
^
jdep.java:10: warning: [deprecation] jdep in unnamed package has been deprecated
return new jdep();
^
2 warnings
Asked at https://discord.com/channels/632150470000902164/632150470000902166/1186776168020582400