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

+3-2
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

-5
This file was deleted.

scala3doc-testcases/src/tests/annotations.scala

+3-1
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

+2-2
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

+2-2
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

+1-1
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

tests/run/generic/Test.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ object Test {
6969
sds(data4)
7070
assert(sCount == 1, sCount)
7171
}
72-
}
72+
}

tests/run/generic/Tree.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Shapes._
1212
* case If(cond: Boolean, thenp: Tree[T], elsep: Tree[T])
1313
* }
1414
*/
15-
sealed trait Tree[TR] extends Enum
15+
sealed trait Tree[TR] extends EnumLike
1616

1717
object Tree {
1818

tests/semanticdb/expect/Enums.expect.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object Enums/*<-_empty_::Enums.*/:
5454

5555
val some1/*<-_empty_::Enums.some1.*/ = /*->_empty_::Enums.unwrap().*/Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1))/*->_empty_::Enums.`<:<`.given_T().*/.unwrap
5656

57-
enum Planet/*<-_empty_::Enums.Planet#*/(mass/*<-_empty_::Enums.Planet#mass.*/: Double/*->scala::Double#*/, radius/*<-_empty_::Enums.Planet#radius.*/: Double/*->scala::Double#*/) extends java.lang.Enum/*->java::lang::Enum#*/[Planet/*->_empty_::Enums.Planet#*/]/*->java::lang::Enum#`<init>`().*/:
57+
enum Planet/*<-_empty_::Enums.Planet#*/(mass/*<-_empty_::Enums.Planet#mass.*/: Double/*->scala::Double#*/, radius/*<-_empty_::Enums.Planet#radius.*/: Double/*->scala::Double#*/) extends Enum/*->java::lang::Enum#*/[Planet/*->_empty_::Enums.Planet#*/]/*->java::lang::Enum#`<init>`().*/:
5858
private final val G/*<-_empty_::Enums.Planet#G.*/ = 6.67300E-11
5959
def surfaceGravity/*<-_empty_::Enums.Planet#surfaceGravity().*/ = G/*->_empty_::Enums.Planet#G.*/ */*->scala::Double#`*`(+6).*/ mass/*->_empty_::Enums.Planet#mass.*/ //*->scala::Double#`::`(+6).*/ (radius/*->_empty_::Enums.Planet#radius.*/ */*->scala::Double#`*`(+6).*/ radius/*->_empty_::Enums.Planet#radius.*/)
6060
def surfaceWeight/*<-_empty_::Enums.Planet#surfaceWeight().*/(otherMass/*<-_empty_::Enums.Planet#surfaceWeight().(otherMass)*/: Double/*->scala::Double#*/) = otherMass/*->_empty_::Enums.Planet#surfaceWeight().(otherMass)*/ */*->scala::Double#`*`(+6).*/ surfaceGravity/*->_empty_::Enums.Planet#surfaceGravity().*/

tests/semanticdb/expect/Enums.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object Enums:
5454

5555
val some1 = Some(Some(1)).unwrap
5656

57-
enum Planet(mass: Double, radius: Double) extends java.lang.Enum[Planet]:
57+
enum Planet(mass: Double, radius: Double) extends Enum[Planet]:
5858
private final val G = 6.67300E-11
5959
def surfaceGravity = G * mass / (radius * radius)
6060
def surfaceWeight(otherMass: Double) = otherMass * surfaceGravity

tests/semanticdb/metac.expect

+4-6
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ Uri => Enums.scala
642642
Text => empty
643643
Language => Scala
644644
Symbols => 181 entries
645-
Occurrences => 203 entries
645+
Occurrences => 201 entries
646646

647647
Symbols:
648648
_empty_/Enums. => final object Enums
@@ -979,11 +979,9 @@ Occurrences:
979979
[56:20..56:26): Double -> scala/Double#
980980
[56:28..56:34): radius <- _empty_/Enums.Planet#radius.
981981
[56:36..56:42): Double -> scala/Double#
982-
[56:52..56:56): java -> java/
983-
[56:57..56:61): lang -> java/lang/
984-
[56:62..56:66): Enum -> java/lang/Enum#
985-
[56:67..56:73): Planet -> _empty_/Enums.Planet#
986-
[56:74..56:74): -> java/lang/Enum#`<init>`().
982+
[56:52..56:56): Enum -> java/lang/Enum#
983+
[56:57..56:63): Planet -> _empty_/Enums.Planet#
984+
[56:64..56:64): -> java/lang/Enum#`<init>`().
987985
[57:22..57:23): G <- _empty_/Enums.Planet#G.
988986
[58:8..58:22): surfaceGravity <- _empty_/Enums.Planet#surfaceGravity().
989987
[58:25..58:26): G -> _empty_/Enums.Planet#G.

0 commit comments

Comments
 (0)