aboutsummaryrefslogtreecommitdiff
path: root/tests/run/generic/Color.scala
blob: ed248295d83415044246b605e1b72c15fe0f122a (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
package generic

import Shapes._

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

object Color extends EnumValues[Color](3) {

  private def $new(tag: Int, name: String) = new Color {
    def enumTag = tag
    override def toString = name
    registerEnumValue(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.value(x.tag)
    }
}