Skip to content

Commit 231b51f

Browse files
Conform tests to the new Enums API
1 parent 2343830 commit 231b51f

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

0 commit comments

Comments
 (0)