scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

annotations and [package|regular] objects #3115

Open scabug opened 14 years ago

scabug commented 14 years ago

I was hoping to deprecate a package object ("what? already?") since the whole package has moved and that would be the cleanest way to deprecate the forwarding stubs, but:

[scalacfork] /scala/trunk/src/library/scala/util/parsing/syntax/package.scala:14: error: expected start of definition
[scalacfork] package object syntax {
[scalacfork] ^
[scalacfork] one error found

As I began this ticket I thought that deprecating an object tagged everything inside it as deprecated, but that doesn't seem to be the case. It is what I had intended for scala.Math, but now I find that referencing it directly gets the warning, but its contents skate by:

scala> scala.Math   
<console>:5: warning: object Math in package scala is deprecated: use scala.math package instead

scala> scala.Math.Pi
res0: Double = 3.141592653589793

Hopefully there is some remedy possible short of directly annotating all several dozen of scala.Math's members. Actually even that isn't much of a remedy because that code is all shared with the undeprecated scala.math package.

(I know nobody would DREAM of suggesting cutting and pasting, so let's not even go there.)

scabug commented 14 years ago

Imported From: https://issues.scala-lang.org/browse/SI-3115?orig=1 Reporter: @paulp

scabug commented 14 years ago

@odersky said: (In r21100) Closes #3115. Reviw by rytz

scabug commented 12 years ago

@vjovanov said: I am reopening this issue as package objects still can not be deprecated and from the the comments and commits I can not see the clear resolution for that matter.

I would like to deprecate the whole package and I can not do it in any way except by going to all public classes and objects and annotating them with @deprecated. In my case the package has quite a few classes and annotating them is not negligible work.

scabug commented 12 years ago

@paulp said: Yeah, it looks like I did them all manually in scala.Math.

What we need is this:

New meta-annotations in scala.annotation.meta for object and class (of course they can't be called that because the identifiers are reserved) so one can attach an annotation to a package object and designate whether it applies to the package object itself, the whole package, or both. Then the deprecation code has to notice it, which means considering the annotations of all enclosing package objects of any given member when issuing warnings.

scabug commented 7 years ago

@janekdb said: Confirming that package level deprecation remains unimplemented.

Context: https://github.com/scala/scala-parser-combinators/issues/99

Code,

package scala.util.parsing

/**
  * This package was never intended for production use; it's really more of a code sample demonstrating how to use parser combinators.
  *
  * Use [[https://index.scala-lang.org/ The Scala Library Index]] to find alternative JSON parsing libraries.
  */
@deprecated("Use The Scala Library Index to find alternatives: https://index.scala-lang.org/", "1.0.6")
package object json {}

Error,

[error] scala-parser-combinators/shared/src/main/scala/scala/util/parsing/json/package.scala:9: expected start of definition
[error] package object json {}
[error] ^
SethTisue commented 2 years ago

12496 notes that @nowarn is also affected

SethTisue commented 2 years ago

This seems like a good project for an interested contributor.

Is it fixed in Scala 3?

som-snytt commented 2 years ago
//@deprecated("do not even", "1.0")
//package object p

package p {
  @deprecated("do not even", "1.0")
  object `package`

  @deprecated("ancient api", "1.0")
  class C {
    @deprecated("old stuff", "1.0")
    def c = 42
    def d = c
  }
  class D {
    def f(c: C) = c.c
  }
}

This is the working syntax, but it does not suppress the deprecations in D, and certainly doesn't induce deprecation on D.

Same result in Scalae 2 & 3.