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

case class no longer deprecates itself #10071

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/profile/Profiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S

private def doGC(): Unit = {
System.gc()
System.runFinalization()
System.runFinalization(): @nowarn("cat=deprecation") // since Java 18
}

reporter.header(this)
Expand Down
9 changes: 6 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1267,9 +1267,12 @@ abstract class RefChecks extends Transform {
// warnings after the first, but I think it'd be better if we didn't have to
// arbitrarily choose one as more important than the other.
private def checkUndesiredProperties(sym: Symbol, pos: Position): Unit = {
// If symbol is deprecated, and the point of reference is not enclosed
// in either a deprecated member or a scala bridge method, issue a warning.
if (sym.isDeprecated && !currentOwner.ownerChain.exists(x => x.isDeprecated))
// Issue a warning if symbol is deprecated, unless the point of reference is enclosed by a deprecated member,
// or has a deprecated companion.
if (sym.isDeprecated &&
// synthetic calls to deprecated case class constructor
!(sym.isConstructor && sym.owner.isCaseClass && currentOwner.isSynthetic) &&
!currentOwner.ownersIterator.exists(s => s.isDeprecated || s.companionClass.isDeprecated))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition for isSynthetic is unfortunately tweaky. Is there a better way to ask, Did the user introduce this symbol? I might have guessed isArtifact.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using isSynthetic and then trying to get back warnings that should show up, could we do something more specific for case classes?

I'm pushing an attempt, let me know what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is narrowly focused to address that issue. There is no reason to over-generalize.

runReporting.deprecationWarning(pos, sym, currentOwner)

// Similar to deprecation: check if the symbol is marked with @migration
Expand Down
7 changes: 0 additions & 7 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1905,13 +1905,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper

warnTypeParameterShadow(tparams1, clazz)

if (!isPastTyper) {
for (ann <- clazz.getAnnotation(DeprecatedAttr)) {
val m = companionSymbolOf(clazz, context)
if (m != NoSymbol)
m.moduleClass.addAnnotation(AnnotationInfo(ann.atp, ann.args, Nil))
}
}
treeCopy.ClassDef(cdef, typedMods, cdef.name, tparams1, impl2)
.setType(NoType)
} finally {
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/classmanifests_new_deprecations.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// scalac: -deprecation -Xfatal-warnings
// scalac: -Xlint -Werror
//
object Test extends App {
def rcm1[T: scala.reflect.ClassManifest] = ???
Expand Down
15 changes: 15 additions & 0 deletions test/files/neg/t2799.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
t2799.scala:7: warning: trait T is deprecated: other mother
class C[A: T] {
^
t2799.scala:8: warning: trait T is deprecated: other mother
def f = (t: T[A]) => null.asInstanceOf[T[A]]
^
t2799.scala:8: warning: trait T is deprecated: other mother
def f = (t: T[A]) => null.asInstanceOf[T[A]]
^
t2799.scala:9: warning: method int2float in object Int is deprecated (since 2.13.1): Implicit conversion from Int to Float is dangerous because it loses precision. Write `.toFloat` instead.
def g() = implicitly[Int => Float]
^
error: No warnings can be incurred under -Werror.
4 warnings
1 error
10 changes: 10 additions & 0 deletions test/files/neg/t2799.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// scalac: -Xlint -Werror

@deprecated("other mother", "")
trait T[A]

// warn even though parameter is synthetic
class C[A: T] {
def f = (t: T[A]) => null.asInstanceOf[T[A]]
def g() = implicitly[Int => Float]
}
5 changes: 1 addition & 4 deletions test/files/neg/t8685.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
t8685.scala:8: warning: constructor D in class D is deprecated (since now): ctor D is depr
case class D @deprecated("ctor D is depr", since="now") (i: Int)
^
t8685.scala:37: warning: class C is deprecated (since now): class C is depr
def f = C(42)
^
Expand Down Expand Up @@ -44,5 +41,5 @@ t8685.scala:55: warning: class K in object J is deprecated (since now): Inner K
def l = new J.K(42)
^
error: No warnings can be incurred under -Werror.
15 warnings
14 warnings
1 error
13 changes: 9 additions & 4 deletions test/files/pos/t2799.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

// scalac: -deprecation -Xfatal-warnings
//
// companion is also deprecated to avoid warning
//
// scalac: -Xlint -Werror

@deprecated("hi mom", "") case class Bob ()

@deprecated("other mother", "")
trait T

object T extends T {
def t = Bob()
}