From edaf481155a550c2b5199de6702c7cbdc2007d58 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 5 Mar 2012 16:05:07 +0100 Subject: new and updated test cases for value classes. --- test/files/neg/t900.check | 4 ++-- test/files/neg/valueclasses.scala | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'test/files/neg') 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) +} +} -- cgit v1.2.3