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

Scalac report a deprecation warning inconsistently between var and def #11538

Open
exoego opened this issue May 16, 2019 · 1 comment

Comments

Projects
None yet
4 participants
@exoego
Copy link

commented May 16, 2019

Scalac report a warning on @deprecated(...) var if its type contains deprecated type.

@deprecated("Non-standard", "0.1")
class StreatmEvent {}

class RTCPeerConnection {
  @deprecated("Non-standard", "0.1")
  var onaddstream: js.Function1[StreatmEvent, _] = js.native
}

However, inconsitently, scalac does not report a warning on @deprecated(...) def that uses deprecated type.

@deprecated("Non-standard", "0.1")
class StreatmEvent {}

class RTCPeerConnection {
  @deprecated("Non-standard", "0.1")
  def onaddstream: js.Function1[StreatmEvent , _] = js.native

  @deprecated("Non-standard", "0.1")
  def onaddstream_= (handler: js.Function1[StreatmEvent , _]): Unit = js.native
}

For me working on scala-js/scala-js-dom#367, no warnings on member already marked as @deprecated is preferrable.
But it may depends on use case.

cc: @sjrd scala-js/scala-js-dom#367 (comment)

@som-snytt

This comment has been minimized.

Copy link

commented May 17, 2019

The annotation isn't winding up on the field. (Same issue with val.)

I looked at how it's done and went blind. Annotations from trees have to be attached to symbols. Possibly they are rethinking the mechanism #10459 I ran out of morning coffee before I saw why getters and setters work but not the field sym.

hrhino added a commit to scala/scala that referenced this issue Jun 5, 2019

Also deprecate backing field symbols.
Compiling
    @deprecated val foo: T = some.deprecated(call)
yielded
    private[this] val `foo `: T = some.deprecated(call)
    @deprecated <accessor> def foo: T = this.`foo `
where the `@deprecated` has been slapped on the def (where it'll incur
deprecation warnings on callers) but not on the val (where it'll
suppress deprecation warnings on the body.

Just copy the annotation across.

Fixes scala/bug#11538 in an expedient manner.

@hrhino hrhino self-assigned this Jun 5, 2019

@hrhino hrhino added the has PR label Jun 5, 2019

@hrhino hrhino added this to the 2.12.9 milestone Jun 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.