From 3e0cd7e7488477e60eb8d12ffeea1b3dc02433a5 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 4 Sep 2008 16:33:51 +0000 Subject: now checking for volatile types. --- test/files/neg/bug412.check | 9 ++++----- test/files/neg/bug414.check | 5 +++++ test/files/neg/bug692.check | 14 +++++++------- test/files/neg/bug692.scala | 4 ++-- test/files/neg/bug961.check | 7 ++++++- test/files/neg/null-unsoundness.check | 5 +++++ test/files/neg/null-unsoundness.scala | 15 +++++++++++++++ test/files/pos/jesper.scala | 30 ++++++++++++++++++++++++++++++ test/files/pos/typesafecons.scala | 30 ++++++++++++++++++++++++++++++ 9 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 test/files/neg/null-unsoundness.check create mode 100644 test/files/neg/null-unsoundness.scala create mode 100644 test/files/pos/jesper.scala create mode 100644 test/files/pos/typesafecons.scala (limited to 'test/files') diff --git a/test/files/neg/bug412.check b/test/files/neg/bug412.check index e275c5d271..f25ad6fa7e 100644 --- a/test/files/neg/bug412.check +++ b/test/files/neg/bug412.check @@ -1,6 +1,5 @@ -bug412.scala:9: error: type mismatch; - found : Null(null) - required: A.this.CX with A.this.C2 - val c: CX with C2 = null; - ^ +bug412.scala:11: error: stable identifier required, but A.this.c found. + Note that value c is not stable because its type, A.this.CX with A.this.C2, is volatile. + def castA(x: c.T): T2 = x; + ^ one error found diff --git a/test/files/neg/bug414.check b/test/files/neg/bug414.check index ec23e26337..c0f039ad26 100644 --- a/test/files/neg/bug414.check +++ b/test/files/neg/bug414.check @@ -1,3 +1,7 @@ +bug414.scala:1: warning: case classes without a parameter list have been deprecated; +use either case objects or case classes with `()' as parameter list. +case class Empty[a] extends IntMap[a]; + ^ bug414.scala:5: error: pattern type is incompatible with expected type; found : object Empty required: IntMap[a] @@ -8,4 +12,5 @@ bug414.scala:7: error: type mismatch; required: a case _ => ^ +one warning found two errors found diff --git a/test/files/neg/bug692.check b/test/files/neg/bug692.check index 308048b80a..099a261f42 100644 --- a/test/files/neg/bug692.check +++ b/test/files/neg/bug692.check @@ -1,19 +1,19 @@ bug692.scala:3: error: not found: type T - trait Type[T0] extends Type0[T]; + trait Type[T0] extends Type0[T]; ^ bug692.scala:10: error: class Foo takes type parameters - case class FooType extends ClassType[Foo,AnyRef](ObjectType()); - ^ + case class FooType() extends ClassType[Foo,AnyRef](ObjectType()); + ^ bug692.scala:13: error: class Foo takes type parameters - case class BarType[T3 <: Foo](tpeT : RefType[T3]) extends ClassType[Bar[T3],Foo](FooType); + case class BarType[T3 <: Foo](tpeT : RefType[T3]) extends ClassType[Bar[T3],Foo](FooType); ^ bug692.scala:13: error: class Foo takes type parameters - case class BarType[T3 <: Foo](tpeT : RefType[T3]) extends ClassType[Bar[T3],Foo](FooType); + case class BarType[T3 <: Foo](tpeT : RefType[T3]) extends ClassType[Bar[T3],Foo](FooType); ^ bug692.scala:19: error: class Foo takes type parameters - class Bar[A <: Foo](implicit tpeA : Type[A]) extends Foo; + class Bar[A <: Foo](implicit tpeA : Type[A]) extends Foo; ^ bug692.scala:14: error: class Foo takes type parameters - implicit def typeOfBar[T4 <: Foo](implicit elem : RefType[T4]) : RefType[Bar[T4]] = + implicit def typeOfBar[T4 <: Foo](implicit elem : RefType[T4]) : RefType[Bar[T4]] = ^ 6 errors found diff --git a/test/files/neg/bug692.scala b/test/files/neg/bug692.scala index 184a14b4b6..24e1d2fea3 100644 --- a/test/files/neg/bug692.scala +++ b/test/files/neg/bug692.scala @@ -3,11 +3,11 @@ abstract class test3 { trait Type[T0] extends Type0[T]; trait ClassType0[+C <: AnyRef] extends Type0[C]; abstract class RefType[C <: AnyRef] extends Type[C]; - case class ObjectType extends RefType[AnyRef]; + case class ObjectType() extends RefType[AnyRef]; abstract class ClassType[C <: Z, Z <: AnyRef](zuper : RefType[Z]) extends RefType[C]; - case class FooType extends ClassType[Foo,AnyRef](ObjectType()); + case class FooType() extends ClassType[Foo,AnyRef](ObjectType()); implicit def typeOfFoo = FooType(); case class BarType[T3 <: Foo](tpeT : RefType[T3]) extends ClassType[Bar[T3],Foo](FooType); diff --git a/test/files/neg/bug961.check b/test/files/neg/bug961.check index 794acf5519..33bb0559b1 100644 --- a/test/files/neg/bug961.check +++ b/test/files/neg/bug961.check @@ -1,4 +1,9 @@ +bug961.scala:4: warning: case classes without a parameter list have been deprecated; +use either case objects or case classes with `()' as parameter list. + private case class B_inner extends A + ^ bug961.scala:11: error: Temp.this.B of type object Temp.B does not take parameters - B() match { + B() match { ^ +one warning found one error found diff --git a/test/files/neg/null-unsoundness.check b/test/files/neg/null-unsoundness.check new file mode 100644 index 0000000000..5f28e76d06 --- /dev/null +++ b/test/files/neg/null-unsoundness.check @@ -0,0 +1,5 @@ +null-unsoundness.scala:8: error: stable identifier required, but A.this.x found. + Note that value x is not stable because its type, A.this.D with A.this.A, is volatile. + var y: x.T = new C("abc") + ^ +one error found diff --git a/test/files/neg/null-unsoundness.scala b/test/files/neg/null-unsoundness.scala new file mode 100644 index 0000000000..d30ff613b1 --- /dev/null +++ b/test/files/neg/null-unsoundness.scala @@ -0,0 +1,15 @@ +class B +class C(x: String) extends B + +class A { + type A >: Null + class D { type T >: C <: B } + val x: D with A = null + var y: x.T = new C("abc") +} +object Test extends A with Application { + class C { type T = Int; val x = 1 } + type A = C + y = 42 +} + diff --git a/test/files/pos/jesper.scala b/test/files/pos/jesper.scala new file mode 100644 index 0000000000..b2a027b0f2 --- /dev/null +++ b/test/files/pos/jesper.scala @@ -0,0 +1,30 @@ +object Pair { + sealed trait Pair { + type First + type Second <: Pair + } + + case class End extends Pair { + type First = Nothing + type Second = End + + def ::[T](v : T) : Cons[T, End] = Cons(v, this) + } + + case object End extends End + + final case class Cons[T1, T2 <: Pair](_1 : T1, _2 : T2) extends Pair { + type First = T1 + type Second = T2 + + def ::[T](v : T) : Cons[T, Cons[T1, T2]] = Cons(v, this) + def find[T](implicit finder : Cons[T1, T2] => T) = finder(this) + } + + implicit def findFirst[T1, T2 <: Pair] : Cons[T1, T2] => T1 = (p : Cons[T1, T2]) => p._1 + implicit def findSecond[T, T1, T2 <: Pair](implicit finder : T2 => T) : Cons[T1, T2] => T = (p : Cons[T1, T2]) => finder(p._2) + + val p : Cons[Int, Cons[Boolean, End]] = 10 :: false :: End +// val x : Boolean = p.find[Boolean](findSecond(findFirst)) + val x2 : Boolean = p.find[Boolean] // Doesn't compile +} diff --git a/test/files/pos/typesafecons.scala b/test/files/pos/typesafecons.scala new file mode 100644 index 0000000000..b2a027b0f2 --- /dev/null +++ b/test/files/pos/typesafecons.scala @@ -0,0 +1,30 @@ +object Pair { + sealed trait Pair { + type First + type Second <: Pair + } + + case class End extends Pair { + type First = Nothing + type Second = End + + def ::[T](v : T) : Cons[T, End] = Cons(v, this) + } + + case object End extends End + + final case class Cons[T1, T2 <: Pair](_1 : T1, _2 : T2) extends Pair { + type First = T1 + type Second = T2 + + def ::[T](v : T) : Cons[T, Cons[T1, T2]] = Cons(v, this) + def find[T](implicit finder : Cons[T1, T2] => T) = finder(this) + } + + implicit def findFirst[T1, T2 <: Pair] : Cons[T1, T2] => T1 = (p : Cons[T1, T2]) => p._1 + implicit def findSecond[T, T1, T2 <: Pair](implicit finder : T2 => T) : Cons[T1, T2] => T = (p : Cons[T1, T2]) => finder(p._2) + + val p : Cons[Int, Cons[Boolean, End]] = 10 :: false :: End +// val x : Boolean = p.find[Boolean](findSecond(findFirst)) + val x2 : Boolean = p.find[Boolean] // Doesn't compile +} -- cgit v1.2.3