Skip to content

fix #10247: skip deprecation warnings in synthetic definitions #10996

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 1 commit into from

Conversation

bishabosha
Copy link
Member

@bishabosha bishabosha commented Jan 4, 2021

fixes #10247

In this change we avoid all deprecation warnings when directly within a synthetic definition.

perhaps this is too permissive? i.e. Is there a place desirable for a synthetic def to warn about calling a deprecated member?

e.g. in this example in issue #10247 the enum case Red is deprecated, but is used to define both the values array and the valueOf lookup method, but these should not cause warnings

@smarter
Copy link
Member

smarter commented Jan 5, 2021

perhaps this is too permissive? i.e. Is there a place desirable for a synthetic def to warn about calling a deprecated member?

Yes, user code can be moved inside a synthetic definition (for example, the body of an anonymous class, the body of a lambda, etc). How does Scala 2 deal with this problem?

@smarter smarter assigned bishabosha and unassigned smarter and odersky Jan 5, 2021
@bishabosha
Copy link
Member Author

scala 2 does the same:
https://github.com/scala/scala/blob/01fba6681110b1afddd2aeb8b009ee83c67e6aad/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala#L1279

with configurable warnings ported you could suppress deprecation warnings with a @nowarn annotation on $values and valueOf. Otherwise this problem would need a special case to scan for methods looking like those and defined in the companion of an enum

@smarter
Copy link
Member

smarter commented Jan 5, 2021

Is it the same? I see that it skips deprecated warning inside deprecated definition but I don't see anything about synthetic.

@bishabosha
Copy link
Member Author

Is it the same? I see that it skips deprecated warning inside deprecated definition but I don't see anything about synthetic.

sorry I meant the same as status quo in Dotty

@bishabosha
Copy link
Member Author

bishabosha commented Jan 5, 2021

Final alternative could scan for @nowarn annotation with no argument, as that is the default behaviour in scala 2. Which that special case should then be removed when the full configurable warnings feature is ported

@smarter
Copy link
Member

smarter commented Jan 5, 2021

If we can't find other problematic cases than enums then I would just special case that: a deprecated enum case used anywhere inside the enum { ... } block where it's defined should not lead to warnings (so the user can use it in defs inside the enum too).

@bishabosha
Copy link
Member Author

bishabosha commented Jan 5, 2021

If we can't find other problematic cases than enums then I would just special case that: a deprecated enum case used anywhere inside the enum { ... } block where it's defined should not lead to warnings (so the user can use it in defs inside the enum too).

^ This would be fine with me.

for the sake of a counter argument Scala 2 would complain about using a deprecated definition in the same scope it is declared:

sealed trait Color
object Color {
  @deprecated("stop using Red") case object Red extends Color
  case object Green extends Color
  case object Blue extends Color
  def values = Array(Red, Green, Blue)
//                   ^
//  6: warning: object Red in object Color is deprecated: stop using Red
}

Overall, I agree it would be consistent to apply the rule across a whole enum declaration. This would allow for layering on top a model for enums that can deprecate cases

@bishabosha bishabosha marked this pull request as draft January 5, 2021 17:25
@bishabosha
Copy link
Member Author

will reopen a new pr with the different changes

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.

Avoid warning about deprecated enum case at definition
3 participants