Skip to content

Commit 3ef8e9c

Browse files
committed
Improve when deprecation warning are emitted
1 parent 5c628d9 commit 3ef8e9c

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ class CrossVersionChecks extends MiniPhase:
159159
val tpe = tree.tpe
160160
tpe.foreachPart {
161161
case TypeRef(_, sym: Symbol) =>
162-
checkDeprecated(sym, tree.srcPos)
162+
if tree.span.isSourceDerived then
163+
checkDeprecated(sym, tree.srcPos)
163164
checkExperimentalRef(sym, tree.srcPos)
164165
case TermRef(_, sym: Symbol) =>
165-
checkDeprecated(sym, tree.srcPos)
166+
if tree.span.isSourceDerived then
167+
checkDeprecated(sym, tree.srcPos)
166168
checkExperimentalRef(sym, tree.srcPos)
167169
case _ =>
168170
}

tests/warn/i19302.check

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Deprecation Warning: tests/warn/i19302.scala:8:20 -------------------------------------------------------------------
2+
8 | def doo(): Option[Thing] = // warn
3+
| ^^^^^
4+
| class Thing is deprecated since n/a: is deprecated
5+
-- Deprecation Warning: tests/warn/i19302.scala:9:13 -------------------------------------------------------------------
6+
9 | Some(new Thing(1)) // warn
7+
| ^^^^^
8+
| class Thing is deprecated since n/a: is deprecated
9+
-- Deprecation Warning: tests/warn/i19302.scala:10:23 ------------------------------------------------------------------
10+
10 | def wop(x: => Option[Thing]) = println(x) // warn
11+
| ^^^^^
12+
| class Thing is deprecated since n/a: is deprecated
13+
-- Deprecation Warning: tests/warn/i19302.scala:13:16 ------------------------------------------------------------------
14+
13 | doo().map((t: Thing) => println(t)) // warn
15+
| ^^^^^
16+
| class Thing is deprecated since n/a: is deprecated
17+
-- Deprecation Warning: tests/warn/i19302.scala:18:18 ------------------------------------------------------------------
18+
18 | val thing = new Thing(42) // warn
19+
| ^^^^^
20+
| class Thing is deprecated since n/a: is deprecated

tests/warn/i19302.scala

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//> using options -deprecation
2+
3+
@deprecated("is deprecated", "n/a")
4+
class Thing(val value: Int)
5+
6+
object Main extends App {
7+
8+
def doo(): Option[Thing] = // warn
9+
Some(new Thing(1)) // warn
10+
def wop(x: => Option[Thing]) = println(x) // warn
11+
12+
doo().map(t => println(t))
13+
doo().map((t: Thing) => println(t)) // warn
14+
doo().map(println)
15+
doo().foreach(println)
16+
for (x <- doo()) println(x)
17+
18+
val thing = new Thing(42) // warn
19+
println(thing)
20+
21+
val something = Some(thing)
22+
wop(something)
23+
}

0 commit comments

Comments
 (0)