Skip to content

remove scala.Enum type alias #10266

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 2 commits into from
Nov 17, 2020
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
5 changes: 3 additions & 2 deletions docs/docs/reference/enums/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ object Planet {
```

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

```scala
enum Color extends java.lang.Enum[Color] { case Red, Green, Blue }
enum Color extends Enum[Color] { case Red, Green, Blue }
```

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.
Expand Down
5 changes: 0 additions & 5 deletions library/src/scala/Enum.scala

This file was deleted.

4 changes: 3 additions & 1 deletion scala3doc-testcases/src/tests/annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package annotations

import scala.annotation.StaticAnnotation

import java.lang.{Enum => _}
import scala.reflect.Enum

class SomeObject(val s: String)

Expand All @@ -25,4 +27,4 @@ class AnnotatedMethods
{
@MyAnnotation @AnnotationWithMultiArg(2, "cda", 'a', 'b', 'c') def a: String
= ???
}
}
2 changes: 1 addition & 1 deletion tests/pos/enum-companion-first.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object Planet:
final val G = 6.67300E-11

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

Expand Down
2 changes: 1 addition & 1 deletion tests/pos/t7716.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object Test {
def test: Unit = {
val e: java.lang.Enum[_] = java.util.concurrent.TimeUnit.SECONDS
val e: Enum[_] = java.util.concurrent.TimeUnit.SECONDS
e match { case x => println(x) }


Expand Down
4 changes: 2 additions & 2 deletions tests/run/enum-custom-toString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum EJ extends java.lang.Enum[EJ]:
case B
override def toString: String = "overridden"

trait Mixin extends Enum:
trait Mixin extends reflect.Enum:
override def productPrefix: String = "noprefix"
override def toString: String = "overridden"

Expand Down Expand Up @@ -36,7 +36,7 @@ enum EQ:
case J extends EQ with Mixin
case K(arg: Int) extends EQ with Mixin

abstract class Tag[T] extends Enum
abstract class Tag[T] extends reflect.Enum
object Tag:
private final class IntTagImpl extends Tag[Int] with runtime.EnumValue:
def ordinal = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/run/generic/Color.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Shapes._
* case Blue
* }
*/
sealed trait Color extends Enum
sealed trait Color extends EnumLike

object Color {

Expand Down
4 changes: 2 additions & 2 deletions tests/run/generic/Enum.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package generic

trait Enum {
trait EnumLike {
def ordinal: Int
}

object runtime {
class EnumValues[E <: Enum] {
class EnumValues[E <: EnumLike] {
private[this] var myMap: Map[Int, E] = Map()
private[this] var fromNameCache: Map[String, E] = null

Expand Down
4 changes: 2 additions & 2 deletions tests/run/generic/List.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Shapes._
* case Nil()
* }
*/
sealed trait List0[T] extends Enum
sealed trait List0[T] extends EnumLike
object List0 {
abstract case class Cons[T](hd: T, tl: List0[T]) extends List0[T] {
def ordinal = 0
Expand Down Expand Up @@ -51,7 +51,7 @@ object List0 {
* case Nil extends List[Nothing]
* }
*/
sealed trait List[+T] extends Enum
sealed trait List[+T] extends EnumLike
object List {
abstract case class Cons[T](hd: T, tl: List[T]) extends List[T] {
def ordinal = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/run/generic/SearchResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Shapes._
* case Ambiguous(alt1: SearchResult, alt2: SearchResult)
* }
*/
sealed trait SearchResult extends Enum
sealed trait SearchResult extends EnumLike

object SearchResult {

Expand Down
2 changes: 1 addition & 1 deletion tests/run/generic/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ object Test {
sds(data4)
assert(sCount == 1, sCount)
}
}
}
2 changes: 1 addition & 1 deletion tests/run/generic/Tree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Shapes._
* case If(cond: Boolean, thenp: Tree[T], elsep: Tree[T])
* }
*/
sealed trait Tree[TR] extends Enum
sealed trait Tree[TR] extends EnumLike

object Tree {

Expand Down
2 changes: 1 addition & 1 deletion tests/semanticdb/expect/Enums.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object Enums/*<-_empty_::Enums.*/:

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

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>`().*/:
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>`().*/:
private final val G/*<-_empty_::Enums.Planet#G.*/ = 6.67300E-11
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.*/)
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().*/
Expand Down
2 changes: 1 addition & 1 deletion tests/semanticdb/expect/Enums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object Enums:

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

enum Planet(mass: Double, radius: Double) extends java.lang.Enum[Planet]:
enum Planet(mass: Double, radius: Double) extends Enum[Planet]:
private final val G = 6.67300E-11
def surfaceGravity = G * mass / (radius * radius)
def surfaceWeight(otherMass: Double) = otherMass * surfaceGravity
Expand Down
10 changes: 4 additions & 6 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ Uri => Enums.scala
Text => empty
Language => Scala
Symbols => 181 entries
Occurrences => 203 entries
Occurrences => 201 entries

Symbols:
_empty_/Enums. => final object Enums
Expand Down Expand Up @@ -979,11 +979,9 @@ Occurrences:
[56:20..56:26): Double -> scala/Double#
[56:28..56:34): radius <- _empty_/Enums.Planet#radius.
[56:36..56:42): Double -> scala/Double#
[56:52..56:56): java -> java/
[56:57..56:61): lang -> java/lang/
[56:62..56:66): Enum -> java/lang/Enum#
[56:67..56:73): Planet -> _empty_/Enums.Planet#
[56:74..56:74): -> java/lang/Enum#`<init>`().
[56:52..56:56): Enum -> java/lang/Enum#
[56:57..56:63): Planet -> _empty_/Enums.Planet#
[56:64..56:64): -> java/lang/Enum#`<init>`().
[57:22..57:23): G <- _empty_/Enums.Planet#G.
[58:8..58:22): surfaceGravity <- _empty_/Enums.Planet#surfaceGravity().
[58:25..58:26): G -> _empty_/Enums.Planet#G.
Expand Down