diff options
author | Martin Odersky <odersky@gmail.com> | 2012-02-19 18:02:44 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2012-02-19 18:03:19 +0100 |
commit | 64aaef72504b46b9d40359eb0476ad8416f36023 (patch) | |
tree | cb41068323ee789847e287a9caf6695856580f16 /test/files/run | |
parent | 8cc7de74d35b437b7126d02a6219796b5872ac14 (diff) | |
download | scala-64aaef72504b46b9d40359eb0476ad8416f36023.tar.gz scala-64aaef72504b46b9d40359eb0476ad8416f36023.tar.bz2 scala-64aaef72504b46b9d40359eb0476ad8416f36023.zip |
Implemented super access in value classes, restrictions for value classes.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/GenericValueClass.scala | 12 | ||||
-rw-r--r-- | test/files/run/Meter.check | 13 | ||||
-rw-r--r-- | test/files/run/Meter.scala | 55 | ||||
-rw-r--r-- | test/files/run/programmatic-main.check | 4 |
4 files changed, 50 insertions, 34 deletions
diff --git a/test/files/run/GenericValueClass.scala b/test/files/run/GenericValueClass.scala deleted file mode 100644 index 10068d6cae..0000000000 --- a/test/files/run/GenericValueClass.scala +++ /dev/null @@ -1,12 +0,0 @@ -class Box[T](val x: T) extends AnyVal { - def get: T = x -} - -object Test extends App { - val b = new Box(1) - println(b.get) - - val c = new Box("abc") - println(c.get) - -} diff --git a/test/files/run/Meter.check b/test/files/run/Meter.check index d5073b3c31..7562f9a1bf 100644 --- a/test/files/run/Meter.check +++ b/test/files/run/Meter.check @@ -9,10 +9,13 @@ a == b: true testing native arrays Array(1.0m, 2.0m) 1.0m -1.0m 1.0m -2.0m 2.0m +>>>1.0m<<< 1.0m +>>>2.0m<<< 2.0m testing wrapped arrays -RowFactory(1.0m, 2.0m) +FlatArray(1.0m, 2.0m) 1.0m -1.0m 1.0m -2.0m 2.0m +>>>1.0m<<< 1.0m +>>>2.0m<<< 2.0m +FlatArray(2.0m, 3.0m) +ArrayBuffer(1.0, 2.0) +FlatArray(0.3048ft, 0.6096ft) diff --git a/test/files/run/Meter.scala b/test/files/run/Meter.scala index 936b8d98b7..42a3aac5f8 100644 --- a/test/files/run/Meter.scala +++ b/test/files/run/Meter.scala @@ -1,23 +1,46 @@ -class Meter(val underlying: Double) extends AnyVal with Printable { - def + (other: Meter): Meter = - new Meter(this.underlying + other.underlying) - def / (other: Meter): Double = this.underlying / other.underlying - def / (factor: Double): Meter = new Meter(this.underlying / factor) - def < (other: Meter): Boolean = this.underlying < other.underlying - override def toString: String = underlying.toString+"m" -} -object Meter extends (Double => Meter) { +package a { + class Meter(val underlying: Double) extends AnyVal with _root_.b.Printable { + def + (other: Meter): Meter = + new Meter(this.underlying + other.underlying) + def / (other: Meter): Double = this.underlying / other.underlying + def / (factor: Double): Meter = new Meter(this.underlying / factor) + def < (other: Meter): Boolean = this.underlying < other.underlying + def toFoot: Foot = new Foot(this.underlying * 0.3048) + override def print = { Console.print(">>>"); super.print; proprint } + override def toString: String = underlying.toString+"m" + } - def apply(x: Double): Meter = new Meter(x) + object Meter extends (Double => Meter) { + + def apply(x: Double): Meter = new Meter(x) - implicit val boxings = new BoxingConversions[Meter, Double] { - def box(x: Double) = new Meter(x) - def unbox(m: Meter) = m.underlying + implicit val boxings = new BoxingConversions[Meter, Double] { + def box(x: Double) = new Meter(x) + def unbox(m: Meter) = m.underlying + } } -} -trait Printable extends Any { def print: Unit = Console.print(this) } + class Foot(val unbox: Double) extends AnyVal { + def + (other: Foot): Foot = + new Foot(this.unbox + other.unbox) + override def toString = unbox.toString+"ft" + } + object Foot { + implicit val boxings = new BoxingConversions[Foot, Double] { + def box(x: Double) = new Foot(x) + def unbox(m: Foot) = m.unbox + } + } +} +package b { + trait Printable extends Any { + def print: Unit = Console.print(this) + protected def proprint = Console.print("<<<") + } +} +import a._ +import _root_.b._ object Test extends App { { @@ -72,6 +95,8 @@ object Test extends App { println(ys) val zs = arr map (_ / Meter(1)) println(zs) + val fs = arr map (_.toFoot) + println(fs) } } diff --git a/test/files/run/programmatic-main.check b/test/files/run/programmatic-main.check index 9ddd4a6e14..d16e2c5178 100644 --- a/test/files/run/programmatic-main.check +++ b/test/files/run/programmatic-main.check @@ -4,8 +4,8 @@ namer 2 resolve names, attach symbols to named trees packageobjects 3 load package objects typer 4 the meat and potatoes: type the trees - extmethods 5 add extension methods for inline classes - superaccessors 6 add super accessors in traits and nested classes + superaccessors 5 add super accessors in traits and nested classes + extmethods 6 add extension methods for inline classes pickler 7 serialize symbol tables refchecks 8 reference/override checking, translate nested objects uncurry 9 uncurry, translate function values to anonymous classes |