Skip to content

Revert "chore: deprecate scala.annotation.transparentTrait" #23129

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

Merged
merged 1 commit into from
May 9, 2025
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
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ class Definitions {
@tu lazy val NowarnAnnot: ClassSymbol = requiredClass("scala.annotation.nowarn")
@tu lazy val UnusedAnnot: ClassSymbol = requiredClass("scala.annotation.unused")
@tu lazy val UnrollAnnot: ClassSymbol = requiredClass("scala.annotation.unroll")
@tu lazy val TransparentTraitAnnot: ClassSymbol = requiredClass("scala.annotation.transparentTrait")
@tu lazy val NativeAnnot: ClassSymbol = requiredClass("scala.native")
@tu lazy val RepeatedAnnot: ClassSymbol = requiredClass("scala.annotation.internal.Repeated")
@tu lazy val RuntimeCheckedAnnot: ClassSymbol = requiredClass("scala.annotation.internal.RuntimeChecked")
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,9 @@ object SymDenotations {
|| accessBoundary(defn.RootClass).isProperlyContainedIn(symbol.topLevelClass)

final def isTransparentClass(using Context): Boolean =
is(TransparentType) || defn.isAssumedTransparent(symbol)
is(TransparentType)
|| defn.isAssumedTransparent(symbol)
|| isClass && hasAnnotation(defn.TransparentTraitAnnot)

/** The class containing this denotation which has the given effective name. */
final def enclosingClassNamed(name: Name)(using Context): Symbol = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ will have type `Int | String` instead of the widened type `Any`.

## Which Traits and Classes Are Transparent?

Traits and classes are declared transparent by adding the modifier `transparent`.
Traits and classes are declared transparent by adding the modifier `transparent`. Scala 2 traits and classes can also be declared transparent by adding a [`@transparentTrait`](https://scala-lang.org/api/3.x/scala/annotation/transparentTrait.html) annotation. This annotation is defined in [`scala.annotation`](https://scala-lang.org/api/3.x/scala/annotation.html). It will be deprecated and phased out once Scala 2/3 interoperability is no longer needed.

The following classes and traits are automatically treated as transparent:
```scala
Expand Down
1 change: 0 additions & 1 deletion library/src/scala/annotation/transparentTrait.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ package scala.annotation
* are not inferred when combined with other types in an intersection.
* See reference/other-new-features/transparent-traits.html for details.
*/
@deprecated(message = "Transparent traits/classes via annotations is no longer supported. Use instead the `transparent` modifier", since = "3.8.0")
final class transparentTrait extends StaticAnnotation
2 changes: 1 addition & 1 deletion library/src/scala/reflect/Enum.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scala.reflect

/** A base trait of all Scala enum definitions */
transparent trait Enum extends Any, Product, Serializable:
@annotation.transparentTrait trait Enum extends Any, Product, Serializable:

/** A number uniquely identifying a case of an enum */
def ordinal: Int
2 changes: 1 addition & 1 deletion library/src/scala/runtime/EnumValue.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scala.runtime

transparent trait EnumValue extends Product, Serializable:
@annotation.transparentTrait trait EnumValue extends Product, Serializable:
override def canEqual(that: Any) = this eq that.asInstanceOf[AnyRef]
override def productArity: Int = 0
override def productElement(n: Int): Any =
Expand Down
Loading