Skip to content

Commit 7413b09

Browse files
authored
Merge pull request scala#9781 from lrytz/classOfDeprecationBackport
[backport] emit deprecations for classOf arguments
2 parents 7faf0fb + 2f65f62 commit 7413b09

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,10 @@ abstract class RefChecks extends Transform {
18571857
case x @ Select(_, _) =>
18581858
transformSelect(x)
18591859

1860+
case Literal(Constant(tp: Type)) =>
1861+
checkTypeRef(tp, tree, skipBounds = false)
1862+
tree
1863+
18601864
case UnApply(fun, args) =>
18611865
transform(fun) // just make sure we enterReference for unapply symbols, note that super.transform(tree) would not transform(fun)
18621866
// transformTrees(args) // TODO: is this necessary? could there be forward references in the args??
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
classOfDeprecation.scala:6: warning: class C is deprecated (since like, forever): no no!
2+
val t = classOf[C]
3+
^
4+
classOfDeprecation.scala:7: warning: class C is deprecated (since like, forever): no no!
5+
@ann(classOf[C]) def u = 1
6+
^
7+
error: No warnings can be incurred under -Xfatal-warnings.
8+
two warnings found
9+
one error found
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// scalac: -deprecation -Xfatal-warnings
2+
3+
@deprecated("no no!", "like, forever") class C
4+
class ann(x: Any) extends annotation.Annotation
5+
object T {
6+
val t = classOf[C]
7+
@ann(classOf[C]) def u = 1
8+
}

test/files/run/t4813.check

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
warning: two deprecations (since 2.11.0); re-run with -deprecation for details
1+
t4813.scala:19: warning: object DoubleLinkedList in package mutable is deprecated (since 2.11.0): low-level linked lists are deprecated
2+
runTest(DoubleLinkedList(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
3+
^
4+
t4813.scala:19: warning: class DoubleLinkedList in package mutable is deprecated (since 2.11.0): low-level linked lists are deprecated due to idiosyncrasies in interface and incomplete features
5+
runTest(DoubleLinkedList(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
6+
^
7+
t4813.scala:22: warning: object LinkedList in package mutable is deprecated (since 2.11.0): low-level linked lists are deprecated
8+
runTest(LinkedList(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
9+
^
10+
t4813.scala:22: warning: class LinkedList in package mutable is deprecated (since 2.11.0): low-level linked lists are deprecated due to idiosyncrasies in interface and incomplete features
11+
runTest(LinkedList(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
12+
^
13+
t4813.scala:26: warning: class Stack in package mutable is deprecated (since 2.12.0): Stack is an inelegant and potentially poorly-performing wrapper around List. Use a List assigned to a var instead.
14+
runTest(Stack(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
15+
^

test/files/run/t4813.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// scalac: -deprecation
2+
13
import collection.mutable._
24
import reflect._
35

0 commit comments

Comments
 (0)