aboutsummaryrefslogtreecommitdiff
path: root/tests/run/generic/Color.scala
blob: 0a0f3f1e53171344471dbb421f75529ff3d39ce9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package generic

import Shapes._

/** enum Color {
 *    case Red
 *    case Green
 *    case Blue
 *  }
 */
sealed trait Color extends Enum

object Color {

  private val $values = new EnumValues[Color]
  def valueOf: Int => Color = $values
  def values = $values.values

  private def $new(tag: Int, name: String) = new Color {
    def enumTag = tag
    override def toString = name
    $values.register(this)
  }

  val Red: Color = $new(0, "Red")
  val Green: Color = $new(1, "Green")
  val Blue: Color = $new(2, "Blue")

  implicit val ColorShape: Color `shaped` EnumValue[Color] =
    new (Color `shaped` EnumValue[Color]) {
      def toShape(x: Color) = EnumValue(x.enumTag)
      def fromShape(x: EnumValue[Color]) = Color.valueOf(x.tag)
    }
}