Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation is emitted for inferred types #19302

Closed
som-snytt opened this issue Dec 19, 2023 · 0 comments · Fixed by #19621
Closed

Deprecation is emitted for inferred types #19302

som-snytt opened this issue Dec 19, 2023 · 0 comments · Fixed by #19621
Assignees
Labels
better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug itype:enhancement
Milestone

Comments

@som-snytt
Copy link
Contributor

som-snytt commented Dec 19, 2023

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

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 19, 2023
@nicolasstucki nicolasstucki added itype:enhancement better-errors Issues concerned with improving confusing/unhelpful diagnostic messages and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 20, 2023
@hamzaremmal hamzaremmal self-assigned this Feb 5, 2024
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants