aboutsummaryrefslogblamecommitdiff
path: root/tests/run/generic/Color.scala
blob: 7f2a8818c0fc264c6920f5377092dd2c564d69fc (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                               

              
                                                     

                                 
                             



                                                        
                          








                                                            
                                                               
     
 
package generic

import Shapes._

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

object Color {

  private val $values = new runtime.EnumValues[Color]
  def valueOf = $values.fromInt
  def withName = $values.fromName
  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)
    }
}