From 0afd6d1b192900f2a0cda3a8fa3d8498ded91d5f Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 6 Oct 2011 10:00:13 +0000 Subject: Closing soundness hole in variance checking. See SI-5060. Review by odersky. --- test/files/neg/t5060.check | 7 +++++++ test/files/neg/t5060.scala | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/files/neg/t5060.check create mode 100644 test/files/neg/t5060.scala (limited to 'test/files') diff --git a/test/files/neg/t5060.check b/test/files/neg/t5060.check new file mode 100644 index 0000000000..ab860c9d5b --- /dev/null +++ b/test/files/neg/t5060.check @@ -0,0 +1,7 @@ +t5060.scala:2: error: covariant type T occurs in contravariant position in type => Object with ScalaObject{def contains(x: T): Unit} of value foo0 + val foo0 = { + ^ +t5060.scala:6: error: covariant type T occurs in contravariant position in type => Object with ScalaObject{def contains(x: T): Unit} of method foo1 + def foo1 = { + ^ +two errors found diff --git a/test/files/neg/t5060.scala b/test/files/neg/t5060.scala new file mode 100644 index 0000000000..4d934a9a16 --- /dev/null +++ b/test/files/neg/t5060.scala @@ -0,0 +1,19 @@ +class A[+T] { + val foo0 = { + class AsVariantAsIWantToBe { def contains(x: T) = () } + new AsVariantAsIWantToBe + } + def foo1 = { + class VarianceIsTheSpiceOfTypes { def contains(x: T) = () } + new VarianceIsTheSpiceOfTypes + } +} + +object Test { + def main(args: Array[String]): Unit = { + val xs: A[String] = new A[String] + println(xs.foo0 contains "abc") + println((xs: A[Any]).foo0 contains 5) + // java.lang.NoSuchMethodException: A$AsVariantAsIWantToBe$1.contains(java.lang.String) + } +} -- cgit v1.2.3