aboutsummaryrefslogtreecommitdiff
path: root/tests/run/generic/Color.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-01-31 14:46:24 +1100
committerMartin Odersky <odersky@gmail.com>2017-01-31 16:14:18 +1100
commit2294e82f6071dedd43b41af6063da5519fd70884 (patch)
tree313a451914dad079ef2358c19bc242eb8b6a8f03 /tests/run/generic/Color.scala
parentfc2bbfeaaf50c073ff1f22bfd0f3231a0b8d08a1 (diff)
downloaddotty-2294e82f6071dedd43b41af6063da5519fd70884.tar.gz
dotty-2294e82f6071dedd43b41af6063da5519fd70884.tar.bz2
dotty-2294e82f6071dedd43b41af6063da5519fd70884.zip
ADT and Serialization test
The test exercises all the improvements made in previous commits of this branch.
Diffstat (limited to 'tests/run/generic/Color.scala')
-rw-r--r--tests/run/generic/Color.scala30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/run/generic/Color.scala b/tests/run/generic/Color.scala
new file mode 100644
index 000000000..ed248295d
--- /dev/null
+++ b/tests/run/generic/Color.scala
@@ -0,0 +1,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)
+ }
+} \ No newline at end of file