From b7b81ca286b1f426cd19befd50fbc513bb82282f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 1 Nov 2011 17:16:51 +0000 Subject: Fixed type unsoundness problem in t5120 and als... Fixed type unsoundness problem in t5120 and also discovered by roman.kalukiewicz@gmail.com. Fix should be refined further, as I am not convinced we are quite done yet. Review by moors. --- test/files/neg/t3015.check | 6 +++--- test/files/neg/t5120.check | 12 ++++++++++++ test/files/neg/t5120.scala | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 test/files/neg/t5120.check create mode 100644 test/files/neg/t5120.scala (limited to 'test') diff --git a/test/files/neg/t3015.check b/test/files/neg/t3015.check index 6095efc6a7..0b394e23d6 100644 --- a/test/files/neg/t3015.check +++ b/test/files/neg/t3015.check @@ -1,11 +1,11 @@ t3015.scala:7: error: scrutinee is incompatible with pattern type; - found : _$1 where type _$1 + found : _$1 where type +_$1 required: String val b(foo) = "foo" ^ t3015.scala:7: error: type mismatch; - found : _$1(in value foo) where type _$1(in value foo) <: String - required: (some other)_$1(in value foo) where type (some other)_$1(in value foo) + found : String with _$1(in object Test) where type +_$1(in object Test) + required: (some other)_$1(in object Test) where type +(some other)_$1(in object Test) val b(foo) = "foo" ^ two errors found diff --git a/test/files/neg/t5120.check b/test/files/neg/t5120.check new file mode 100644 index 0000000000..34d4ebde31 --- /dev/null +++ b/test/files/neg/t5120.check @@ -0,0 +1,12 @@ +t5120.scala:11: error: type mismatch; + found : Object + required: _1 + List(str, other) foreach (_.x1 = new AnyRef) + ^ +t5120.scala:25: error: type mismatch; + found : Thread + required: h.T + (which expands to) _2 + List(str, num).foreach(h => h.f1 = new Thread()) + ^ +two errors found diff --git a/test/files/neg/t5120.scala b/test/files/neg/t5120.scala new file mode 100644 index 0000000000..f28b2cfb4f --- /dev/null +++ b/test/files/neg/t5120.scala @@ -0,0 +1,29 @@ +class Cell[T](x0: T) { + type U = T + var x1: U = x0 +} + +object Test { + val str: Cell[String] = new Cell("a") + val other: Cell[Int] = new Cell(0) + + def main(args: Array[String]): Unit = { + List(str, other) foreach (_.x1 = new AnyRef) + str.x1.length + } +} +// another way demonstrating the same underlying problem, as reported by roman kalukiewicz + +class Holder[_T](_f1 : _T, _f2 : _T) { + type T = _T + var f1 : T = _f1 + var f2 : T = _f2 +} +object Test2 { + val str = new Holder("t1", "t2") + val num = new Holder(1, 2) + List(str, num).foreach(h => h.f1 = new Thread()) + def main(args: Array[String]) { + println(str.f1) + } +} -- cgit v1.2.3