Skip to content

Commit

Permalink
Improve when deprecation warnings are emitted (scala#19621)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki authored Feb 7, 2024
2 parents f1bad54 + 3ef8e9c commit 551eae4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,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 551eae4

Please sign in to comment.