summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2012-03-05 16:05:07 +0100
committerMartin Odersky <odersky@gmail.com>2012-03-05 16:05:44 +0100
commitedaf481155a550c2b5199de6702c7cbdc2007d58 (patch)
tree1fc03da097d60cdce0e3cd752d768c7864055e07 /test/files
parent0df343a0c614d6a7468105769568b2fba3f9b03c (diff)
downloadscala-edaf481155a550c2b5199de6702c7cbdc2007d58.tar.gz
scala-edaf481155a550c2b5199de6702c7cbdc2007d58.tar.bz2
scala-edaf481155a550c2b5199de6702c7cbdc2007d58.zip
new and updated test cases for value classes.
Diffstat (limited to 'test/files')
-rw-r--r--test/files/neg/t900.check4
-rw-r--r--test/files/neg/valueclasses.scala18
-rw-r--r--test/files/run/genericValueClass.check2
-rw-r--r--test/files/run/genericValueClass.scala17
4 files changed, 39 insertions, 2 deletions
diff --git a/test/files/neg/t900.check b/test/files/neg/t900.check
index cede26258b..047094ad6e 100644
--- a/test/files/neg/t900.check
+++ b/test/files/neg/t900.check
@@ -2,8 +2,8 @@ t900.scala:4: error: type mismatch;
found : Foo.this.x.type (with underlying type Foo.this.bar)
required: AnyRef
Note that implicit conversions are not applicable because they are ambiguous:
- both method any2Ensuring in object Predef of type [A](x: A)Ensuring[A]
- and method any2ArrowAssoc in object Predef of type [A](x: A)ArrowAssoc[A]
+ both method any2stringadd in object Predef of type (x: Any)scala.runtime.StringAdd
+ and method any2stringfmt in object Predef of type (x: Any)scala.runtime.StringFormat
are possible conversion functions from Foo.this.x.type to AnyRef
def break(): x.type
^
diff --git a/test/files/neg/valueclasses.scala b/test/files/neg/valueclasses.scala
index 5979f6f684..e405d95489 100644
--- a/test/files/neg/valueclasses.scala
+++ b/test/files/neg/valueclasses.scala
@@ -31,6 +31,24 @@ class V12[@specialized T, U](val x: (T, U)) extends AnyVal // fail
class V13(x: Int) extends AnyVal // fail
+package time {
+object TOD {
+ final val SecondsPerDay = 86400
+
+ def apply(seconds: Int) = {
+ val n = seconds % SecondsPerDay
+ new TOD(if (n >= 0) n else n + SecondsPerDay)
+ }
+}
+
+final class TOD private (val secondsOfDay: Int) extends AnyVal { // should fail with private constructor
+ def hours = secondsOfDay / 3600
+ def minutes = (secondsOfDay / 60) % 60
+ def seconds = secondsOfDay % 60
+
+ override def toString = "%02d:%02d:%02d".format(hours, minutes, seconds)
+}
+}
diff --git a/test/files/run/genericValueClass.check b/test/files/run/genericValueClass.check
new file mode 100644
index 0000000000..ec3a41a6a9
--- /dev/null
+++ b/test/files/run/genericValueClass.check
@@ -0,0 +1,2 @@
+(1,abc)
+(2,def)
diff --git a/test/files/run/genericValueClass.scala b/test/files/run/genericValueClass.scala
new file mode 100644
index 0000000000..68162bb685
--- /dev/null
+++ b/test/files/run/genericValueClass.scala
@@ -0,0 +1,17 @@
+final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal {
+ @inline def -> [B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y)
+ def →[B](y: B): Tuple2[A, B] = ->(y)
+}
+
+object Test extends App {
+ {
+ @inline implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x)
+ val x = 1 -> "abc"
+ println(x)
+ }
+
+ {
+ val y = 2 -> "def"
+ println(y)
+ }
+}