Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Forward port deprecation exclusion #16918

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

Closed
wants to merge 2 commits into from

Conversation

som-snytt
Copy link
Contributor

Deprecation is suppressed if enclosing element is deprecated; the exclusion is extended to include "if companion of enclosing element is deprecated."

Fixes #11022

Deprecation is suppressed if enclosing element is deprecated;
the exclusion is extended to include "if companion of enclosing
element is deprecated."
@jan-pieter
Copy link
Contributor

Looks like this allows something that was supposed to give a warning (according to #12706 (comment)):

@deprecated("no CaseClass") case class CaseClass(rgb: Int)

object CaseClass:
  def answer: Int = { val x = new CaseClass(42); 42 }

val a = CaseClass.answer

@som-snytt
Copy link
Contributor Author

I disagree with the assertion that the usage in the companion should warn. Deprecation is for API (you can't deprecate local methods, for instance). The interface between companions (in this view) is not deprecatable API. I might deprecate the constructor in favor of the companion apply, for instance. I don't intend to deprecate the method.

(The bug in old Scala 2 was that it intended to deprecate the companion, but did not.)

I'll put more thought into the use cases and whether the community build had an opinion on Scala 2.

@som-snytt
Copy link
Contributor Author

The other example from the linked ticket is scala.io.Position, where object Position extends Position and the class is deprecated.

Clients should not use the class but may use utility methods in the companion.

@jan-pieter
Copy link
Contributor

I think the synthetic methods should trigger the deprecation warning as well; the following code should definitely trigger a warning (and with this change it does not):

@deprecated("no CaseClass") case class CaseClass(rgb: Int):
  def magic(): Unit = ()
  
val a = CaseClass(42).magic()

@som-snytt
Copy link
Contributor Author

Closing until Scala 2 ticket is sorted.

@som-snytt
Copy link
Contributor Author

Note to future self: I changed my mind since Valentine's Day.

The ongoing adjustment on Scala 2 is at scala/scala#10311

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deprecated case class warns at its definition
2 participants