Skip to content

Commit 0c9b2ca

Browse files
authored
Merge pull request #10266 from dotty-staging/topic/enum-delete-scala-enum
remove scala.Enum type alias
2 parents cd15c99 + 88a1c3e commit 0c9b2ca

File tree

15 files changed

+24
-28
lines changed

15 files changed

+24
-28
lines changed

docs/docs/reference/enums/enums.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ object Planet {
8989
```
9090

9191
### Compatibility with Java Enums
92-
If you want to use the Scala-defined enums as Java enums, you can do so by extending `java.lang.Enum` class as follows:
92+
If you want to use the Scala-defined enums as Java enums, you can do so by extending
93+
the class `java.lang.Enum`, which is imported by default, as follows:
9394

9495
```scala
95-
enum Color extends java.lang.Enum[Color] { case Red, Green, Blue }
96+
enum Color extends Enum[Color] { case Red, Green, Blue }
9697
```
9798

9899
The type parameter comes from the Java enum [definition](https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/Enum.html) and should be the same as the type of the enum.

library/src/scala/Enum.scala

Lines changed: 0 additions & 5 deletions
This file was deleted.

scala3doc-testcases/src/tests/annotations.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package annotations
33

44
import scala.annotation.StaticAnnotation
55

6+
import java.lang.{Enum => _}
7+
import scala.reflect.Enum
68

79
class SomeObject(val s: String)
810

@@ -25,4 +27,4 @@ class AnnotatedMethods
2527
{
2628
@MyAnnotation @AnnotationWithMultiArg(2, "cda", 'a', 'b', 'c') def a: String
2729
= ???
28-
}
30+
}

tests/pos/enum-companion-first.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object Planet:
22
final val G = 6.67300E-11
33

4-
enum Planet(mass: Double, radius: Double) extends java.lang.Enum[Planet]:
4+
enum Planet(mass: Double, radius: Double) extends Enum[Planet]:
55
def surfaceGravity = Planet.G * mass / (radius * radius)
66
def surfaceWeight(otherMass: Double) = otherMass * surfaceGravity
77

tests/pos/t7716.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Test {
22
def test: Unit = {
3-
val e: java.lang.Enum[_] = java.util.concurrent.TimeUnit.SECONDS
3+
val e: Enum[_] = java.util.concurrent.TimeUnit.SECONDS
44
e match { case x => println(x) }
55

66

tests/run/enum-custom-toString.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ enum EJ extends java.lang.Enum[EJ]:
66
case B
77
override def toString: String = "overridden"
88

9-
trait Mixin extends Enum:
9+
trait Mixin extends reflect.Enum:
1010
override def productPrefix: String = "noprefix"
1111
override def toString: String = "overridden"
1212

@@ -36,7 +36,7 @@ enum EQ:
3636
case J extends EQ with Mixin
3737
case K(arg: Int) extends EQ with Mixin
3838

39-
abstract class Tag[T] extends Enum
39+
abstract class Tag[T] extends reflect.Enum
4040
object Tag:
4141
private final class IntTagImpl extends Tag[Int] with runtime.EnumValue:
4242
def ordinal = 0

tests/run/generic/Color.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Shapes._
88
* case Blue
99
* }
1010
*/
11-
sealed trait Color extends Enum
11+
sealed trait Color extends EnumLike
1212

1313
object Color {
1414

tests/run/generic/Enum.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package generic
22

3-
trait Enum {
3+
trait EnumLike {
44
def ordinal: Int
55
}
66

77
object runtime {
8-
class EnumValues[E <: Enum] {
8+
class EnumValues[E <: EnumLike] {
99
private[this] var myMap: Map[Int, E] = Map()
1010
private[this] var fromNameCache: Map[String, E] = null
1111

tests/run/generic/List.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Shapes._
77
* case Nil()
88
* }
99
*/
10-
sealed trait List0[T] extends Enum
10+
sealed trait List0[T] extends EnumLike
1111
object List0 {
1212
abstract case class Cons[T](hd: T, tl: List0[T]) extends List0[T] {
1313
def ordinal = 0
@@ -51,7 +51,7 @@ object List0 {
5151
* case Nil extends List[Nothing]
5252
* }
5353
*/
54-
sealed trait List[+T] extends Enum
54+
sealed trait List[+T] extends EnumLike
5555
object List {
5656
abstract case class Cons[T](hd: T, tl: List[T]) extends List[T] {
5757
def ordinal = 0

tests/run/generic/SearchResult.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Shapes._
99
* case Ambiguous(alt1: SearchResult, alt2: SearchResult)
1010
* }
1111
*/
12-
sealed trait SearchResult extends Enum
12+
sealed trait SearchResult extends EnumLike
1313

1414
object SearchResult {
1515

0 commit comments

Comments
 (0)