Skip to content

Commit

Permalink
Improve when deprecation warning are emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Feb 5, 2024
1 parent 5c628d9 commit e2da4b8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import config.{ScalaVersion, NoScalaVersion, Feature, ScalaRelease}
import MegaPhase.MiniPhase
import scala.util.{Failure, Success}
import ast.tpd
import dotty.tools.dotc.transform.init.Util.hasSource

class CrossVersionChecks extends MiniPhase:
import tpd.*
Expand Down Expand Up @@ -159,10 +160,12 @@ class CrossVersionChecks extends MiniPhase:
val tpe = tree.tpe
tpe.foreachPart {
case TypeRef(_, sym: Symbol) =>
checkDeprecated(sym, tree.srcPos)
if tree.span.isSourceDerived then
checkDeprecated(sym, tree.srcPos)
checkExperimentalRef(sym, tree.srcPos)
case TermRef(_, sym: Symbol) =>
checkDeprecated(sym, tree.srcPos)
if tree.span.isSourceDerived then
checkDeprecated(sym, tree.srcPos)
checkExperimentalRef(sym, tree.srcPos)
case _ =>
}
Expand Down
20 changes: 20 additions & 0 deletions tests/warn/i19302.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Deprecation Warning: tests/warn/i19302.scala:8:20 -------------------------------------------------------------------
8 | def doo(): Option[Thing] = // warn
| ^^^^^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: tests/warn/i19302.scala:9:13 -------------------------------------------------------------------
9 | Some(new Thing(1)) // warn
| ^^^^^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: tests/warn/i19302.scala:10:23 ------------------------------------------------------------------
10 | def wop(x: => Option[Thing]) = println(x) // warn
| ^^^^^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: tests/warn/i19302.scala:13:16 ------------------------------------------------------------------
13 | doo().map((t: Thing) => println(t)) // warn
| ^^^^^
| class Thing is deprecated since n/a: is deprecated
-- Deprecation Warning: tests/warn/i19302.scala:18:18 ------------------------------------------------------------------
18 | val thing = new Thing(42) // warn
| ^^^^^
| class Thing is deprecated since n/a: is deprecated
23 changes: 23 additions & 0 deletions tests/warn/i19302.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//> using options -deprecation

@deprecated("is deprecated", "n/a")
class Thing(val value: Int)

object Main extends App {

def doo(): Option[Thing] = // warn
Some(new Thing(1)) // warn
def wop(x: => Option[Thing]) = println(x) // warn

doo().map(t => println(t))
doo().map((t: Thing) => println(t)) // warn
doo().map(println)
doo().foreach(println)
for (x <- doo()) println(x)

val thing = new Thing(42) // warn
println(thing)

val something = Some(thing)
wop(something)
}

0 comments on commit e2da4b8

Please sign in to comment.