Skip to content

Commit 27d4ac6

Browse files
Conform tests to the new Enums API
1 parent e7dc3b9 commit 27d4ac6

File tree

15 files changed

+46
-49
lines changed

15 files changed

+46
-49
lines changed

tests/neg/i5008.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ enum Baz extends Foo { case Z } // error
55
enum Quux extends Foo with Bar { case Z } // error
66

77
class Quuw extends Foo // error
8-
class Quuz extends Foo { val enumTag = 1 } // error
8+
class Quuz extends Foo { val ordinal = 1 } // error

tests/neg/i5019.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
enum A { // error
2-
def newA(tag: Int) = new A { val enumTag = tag } // error
2+
def newA(tag: Int) = new A { val ordinal = tag } // error
33
}

tests/patmat/planets.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ enum Planet(mass: Double, radius: Double) {
1515
object Test {
1616
def main(args: Array[String]) = {
1717
import Planet._
18-
assert(enumValueNamed("SATURN") == SATURN)
19-
assert(enumValue(2) == EARTH)
18+
assert(valueOf("SATURN") == SATURN)
2019
val earthWeight = 100
2120
val mass = earthWeight/EARTH.surfaceGravity
22-
for (p <- enumValues)
21+
for (p <- values)
2322
println(s"Your weight on $p is ${p.surfaceWeight(mass)}")
2423
}
2524
}

tests/pos-with-compiler/tasty/definitions.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ object definitions {
6565
/** Trees denoting terms */
6666
enum Term extends Statement {
6767
def tpe: Type = ???
68-
case Ident(name: String, override val tpe: Type)
69-
case Select(prefix: Term, name: String, signature: Option[Signature])
68+
case Ident(nme: String, override val tpe: Type)
69+
case Select(prefix: Term, nme: String, signature: Option[Signature])
7070
case Literal(value: Constant)
7171
case This(id: Option[Id])
7272
case New(tpt: TypeTree)
7373
case Throw(expr: Term)
74-
case NamedArg(name: String, arg: Term)
74+
case NamedArg(nme: String, arg: Term)
7575
case Apply(fn: Term, args: List[Term])
7676
case TypeApply(fn: Term, args: List[TypeTree])
7777
case Super(thiz: Term, mixin: Option[Id])
@@ -94,9 +94,9 @@ object definitions {
9494
enum TypeTree extends Positioned {
9595
def tpe: Type = ???
9696
case Synthetic()
97-
case Ident(name: String, override val tpe: Type)
98-
case TermSelect(prefix: Term, name: String)
99-
case TypeSelect(prefix: TypeTree, name: String)
97+
case Ident(nme: String, override val tpe: Type)
98+
case TermSelect(prefix: Term, nme: String)
99+
case TypeSelect(prefix: TypeTree, nme: String)
100100
case Singleton(ref: Term)
101101
case Refined(underlying: TypeTree, refinements: List[Definition])
102102
case Applied(tycon: TypeTree, args: List[TypeTree | TypeBoundsTree])
@@ -105,7 +105,7 @@ object definitions {
105105
case Or(left: TypeTree, right: TypeTree)
106106
case ByName(tpt: TypeTree)
107107
case TypeLambda(tparams: List[TypeDef], body: Type | TypeBoundsTree)
108-
case Bind(name: String, bounds: TypeBoundsTree)
108+
case Bind(nme: String, bounds: TypeBoundsTree)
109109
}
110110

111111
/** Trees denoting type bounds */
@@ -122,7 +122,7 @@ object definitions {
122122
enum Pattern extends Positioned {
123123
def tpe: Type = ???
124124
case Value(v: Term)
125-
case Bind(name: String, pat: Pattern)
125+
case Bind(nme: String, pat: Pattern)
126126
case Unapply(unapply: Term, implicits: List[Term], pats: List[Pattern])
127127
case Alternative(pats: List[Pattern])
128128
case TypeTest(tpt: TypeTree)

tests/pos/enum-List-control.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
abstract sealed class List[T] extends Enum
22
object List {
33
final class Cons[T](x: T, xs: List[T]) extends List[T] {
4-
def enumTag = 0
4+
def ordinal = 0
5+
def name = "Cons"
56
}
67
object Cons {
78
def apply[T](x: T, xs: List[T]): List[T] = new Cons(x, xs)
89
}
910
final class Nil[T]() extends List[T] {
10-
def enumTag = 1
11+
def ordinal = 1
12+
def name = "Nil"
1113
}
1214
object Nil {
1315
def apply[T](): List[T] = new Nil()

tests/pos/reference/enums.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object Planet {
4747
def main(args: Array[String]) = {
4848
val earthWeight = args(0).toDouble
4949
val mass = earthWeight/EARTH.surfaceGravity
50-
for (p <- enumValues)
50+
for (p <- values)
5151
println(s"Your weight on $p is ${p.surfaceWeight(mass)}")
5252
}
5353
}

tests/run/enum-Color.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Red: 0
2-
Green: 1
3-
Blue: 2
1+
Red: Red
2+
Green: Green
3+
Blue: Blue

tests/run/enum-Color.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ enum Color {
55

66
object Test {
77
def main(args: Array[String]) =
8-
for (color <- Color.enumValues) {
9-
println(s"$color: ${color.enumTag}")
10-
assert(Color.enumValue(color.enumTag) eq color)
8+
for (color <- Color.values) {
9+
println(s"$color: ${color.name}")
10+
assert(Color.valueOf(color.name) eq color)
1111
import Color._
1212
color match {
1313
case Red | Green | Blue =>

tests/run/generic/Color.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object Color {
1818
def values = $values.values
1919

2020
private def $new(tag: Int, name: String) = new Color {
21-
def enumTag = tag
21+
def ordinal = tag
2222
override def toString = name
2323
$values.register(this)
2424
}
@@ -29,7 +29,7 @@ object Color {
2929

3030
implicit val ColorShape: Color `shaped` EnumValue[Color] =
3131
new (Color `shaped` EnumValue[Color]) {
32-
def toShape(x: Color) = EnumValue(x.enumTag)
32+
def toShape(x: Color) = EnumValue(x.ordinal)
3333
def fromShape(x: EnumValue[Color]) = Color.valueOf(x.tag)
3434
}
3535
}

tests/run/generic/Enum.scala

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

33
trait Enum {
4-
def enumTag: Int
4+
def ordinal: Int
55
}
66

77
object runtime {
@@ -10,8 +10,8 @@ object runtime {
1010
private[this] var fromNameCache: Map[String, E] = null
1111

1212
def register(v: E) = {
13-
require(!myMap.contains(v.enumTag))
14-
myMap = myMap.updated(v.enumTag, v)
13+
require(!myMap.contains(v.ordinal))
14+
myMap = myMap.updated(v.ordinal, v)
1515
fromNameCache = null
1616
}
1717

tests/run/generic/List.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Shapes._
1010
sealed trait List0[T] extends Enum
1111
object List0 {
1212
abstract case class Cons[T](hd: T, tl: List0[T]) extends List0[T] {
13-
def enumTag = 0
13+
def ordinal = 0
1414
}
1515
object Cons {
1616
def apply[T](x: T, xs: List0[T]): List0[T] = new Cons(x, xs) {}
@@ -22,7 +22,7 @@ object List0 {
2222
}
2323

2424
abstract case class Nil[T]() extends List0[T] {
25-
def enumTag = 1
25+
def ordinal = 1
2626
}
2727
object Nil {
2828
def apply[T](): List0[T] = new Nil[T]() {}
@@ -54,7 +54,7 @@ object List0 {
5454
sealed trait List[+T] extends Enum
5555
object List {
5656
abstract case class Cons[T](hd: T, tl: List[T]) extends List[T] {
57-
def enumTag = 0
57+
def ordinal = 0
5858
}
5959
object Cons {
6060
def apply[T](x: T, xs: List[T]): List[T] = new Cons(x, xs) {}
@@ -67,7 +67,7 @@ object List {
6767
}
6868

6969
val Nil = new List[Nothing] {
70-
def enumTag = 1
70+
def ordinal = 1
7171
override def toString = "Nil"
7272
}
7373

tests/run/generic/SearchResult.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ object SearchResult {
1919
def values = $values.values
2020

2121
private def $new(tag: Int, name: String) = new SearchResult {
22-
def enumTag = tag
22+
def ordinal = tag
2323
override def toString = name
2424
$values.register(this)
2525
}
2626

2727
abstract case class Success(result: Color) extends SearchResult {
28-
def enumTag = 0
28+
def ordinal = 0
2929
}
3030
object Success {
3131
def apply(result: Color): SearchResult = new Success(result) {}
@@ -40,7 +40,7 @@ object SearchResult {
4040
val NoMatch: SearchResult = $new(2, "NoMatch")
4141

4242
abstract case class Ambiguous(alt1: SearchResult, alt2: SearchResult) extends SearchResult {
43-
def enumTag = 3
43+
def ordinal = 3
4444
}
4545
object Ambiguous {
4646
def apply(alt1: SearchResult, alt2: SearchResult): SearchResult = new Ambiguous(alt1, alt2) {}
@@ -58,7 +58,7 @@ object SearchResult {
5858
def toShape(x: SearchResult) = x match {
5959
case x: Success => Fst(x)
6060
case x: Ambiguous => Snd(Fst(x))
61-
case x => Snd(Snd(EnumValue(x.enumTag)))
61+
case x => Snd(Snd(EnumValue(x.ordinal)))
6262
}
6363
def fromShape(x: Sum[Success, Sum[Ambiguous, EnumValue[SearchResult]]]): SearchResult = x match {
6464
case Fst(s) => s

tests/run/generic/Tree.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ sealed trait Tree[TR] extends Enum
1717
object Tree {
1818

1919
val True: Tree[Boolean] = new Tree[Boolean] {
20-
def enumTag = 0
20+
def ordinal = 0
2121
override def toString = "True"
2222
}
2323
implicit def TrueSingleton: Singleton[True.type] = new Singleton[True.type](True)
2424

2525
val False: Tree[Boolean] = new Tree[Boolean] {
26-
def enumTag = 1
26+
def ordinal = 1
2727
override def toString = "False"
2828
}
2929
implicit def FalseSingleton: Singleton[False.type] = new Singleton[False.type](False)
3030

3131
val Zero: Tree[Int] = new Tree[Int] {
32-
def enumTag = 2
32+
def ordinal = 2
3333
override def toString = "Zero"
3434
}
3535
implicit def ZeroSingleton: Singleton[Zero.type] = new Singleton[Zero.type](Zero)
3636

3737
abstract case class Succ(n: Tree[Int]) extends Tree[Int] {
38-
def enumTag = 3
38+
def ordinal = 3
3939
}
4040
object Succ {
4141
def apply(x: Tree[Int]): Tree[Int] = new Succ(x) {}
@@ -46,7 +46,7 @@ object Tree {
4646
}
4747

4848
abstract case class Pred(n: Tree[Int]) extends Tree[Int] {
49-
def enumTag = 4
49+
def ordinal = 4
5050
}
5151
object Pred {
5252
def apply(x: Tree[Int]): Tree[Int] = new Pred(x) {}
@@ -57,7 +57,7 @@ object Tree {
5757
}
5858

5959
abstract case class IsZero(n: Tree[Int]) extends Tree[Boolean] {
60-
def enumTag = 5
60+
def ordinal = 5
6161
}
6262
object IsZero {
6363
def apply(x: Tree[Int]): Tree[Boolean] = new IsZero(x) {}
@@ -68,7 +68,7 @@ object Tree {
6868
}
6969

7070
abstract case class If[T](cond: Tree[Boolean], thenp: Tree[T], elsep: Tree[T]) extends Tree[T] {
71-
def enumTag = 6
71+
def ordinal = 6
7272
}
7373
object If {
7474
def apply[T](cond: Tree[Boolean], thenp: Tree[T], elsep: Tree[T]): Tree[T] = new If(cond, thenp, elsep) {}

tests/run/i4961.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
trait Animal
22
object Animal {
3-
def enumValues: Iterable[Animal] = Dog.enumValues ++ Cat.enumValues
4-
def enumValueNamed = Dog.enumValueNamed ++ Cat.enumValueNamed
3+
def enumValues: Iterable[Animal] = Dog.values ++ Cat.values
54
}
65

76
enum Dog extends Animal {
@@ -27,7 +26,5 @@ object Test {
2726
)
2827

2928
assert(Animal.enumValues == values)
30-
assert(Animal.enumValueNamed("Boxer") == Boxer)
31-
assert(Animal.enumValueNamed("Ragdoll") == Ragdoll)
3229
}
3330
}

tests/run/planets.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ enum Planet(mass: Double, radius: Double) {
1515
object Test {
1616
def main(args: Array[String]) = {
1717
import Planet._
18-
assert(enumValueNamed("SATURN") == SATURN)
19-
assert(enumValue(2) == EARTH)
18+
assert(valueOf("SATURN") == SATURN)
2019
val earthWeight = 100
2120
val mass = earthWeight/EARTH.surfaceGravity
22-
for (p <- enumValues)
21+
for (p <- values)
2322
println(s"Your weight on $p is ${p.surfaceWeight(mass)}")
2423
}
2524
}

0 commit comments

Comments
 (0)