From 034489b50158756b57091a04830d94160975bddb Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 24 Jun 2011 05:42:08 +0000 Subject: Added sanity check to lub calculation to preven... Added sanity check to lub calculation to prevent invalid lubs from emerging. The underlying cause of said lubs is that higher-order type parameters are not handled correctly: this is why the issue is seen so frequently in the collections. See pending test pending/pos/those-kinds-are-high.scala for a demonstration. Until that's fixed, we can at least raise the bar a bit. Closes #2094, #2322, #4501. Also, some test cases in neg have been promoted into working programs: #2179, #3774. (They're not in neg for the "shouldn't work" reason, but out of despair.) In some cases, such as the original reported ticket in #3528, this only pushes the problem downfield: it still fails due to inferred type parameters not conforming to bounds. I believe a similar issue with higher-order type parameters underlies that. Look at how far this takes us though. All kinds of stuff which did not work, now works. None of these even compiled until now: scala> :type List(mutable.Map(1 -> 1), immutable.Map(1 -> 1)) List[scala.collection.Map[Int,Int]] scala> :type Set(List(1), mutable.Map(1 -> 1)) scala.collection.Set[Iterable[Any] with PartialFunction[Int,Int]] scala> :type Stream(List(1), Set(1), 1 to 5) Stream[Iterable[Int] with Int => AnyVal{def getClass(): Class[_ >: Int with Boolean <: AnyVal]}] scala> :type Map(1 -> (1 to 10), 2 -> (1 to 10).toList) scala.collection.immutable.Map[Int,scala.collection.immutable.Seq[Int] ] PERFORMANCE: compiling quick.lib and quick.comp, this patch results in an extra 27 subtype tests. Total. Time difference too small to measure. However to be on the safe side I made it really easy to disable. private final val verifyLubs = true // set to false Review by moors, odersky. --- test/pending/pos/those-kinds-are-high.scala | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/pending/pos/those-kinds-are-high.scala (limited to 'test/pending') diff --git a/test/pending/pos/those-kinds-are-high.scala b/test/pending/pos/those-kinds-are-high.scala new file mode 100644 index 0000000000..d3ee2bf308 --- /dev/null +++ b/test/pending/pos/those-kinds-are-high.scala @@ -0,0 +1,37 @@ +class A { + trait Container[+T] + trait Template[+CC[X] <: Container[X]] + + class C1[T] extends Template[C1] with Container[T] + class C2[T] extends Template[C2] with Container[T] + + /** Target expression: + * List(new C1[String], new C2[String]) + */ + + // Here's what would ideally be inferred. + // + // scala> :type List[Template[Container] with Container[String]](new C1[String], new C2[String]) + // List[Template[Container] with Container[java.lang.String]] + // + // Here's what it does infer. + // + // scala> :type List(new C1[String], new C2[String]) + // :8: error: type mismatch; + // found : C1[String] + // required: Container[String] with Template[Container[Any] with Template[Container[Any] with Template[Any] with ScalaObject] with ScalaObject] with ScalaObject + // List(new C1[String], new C2[String]) + // ^ + // + // Simplified, the inferred type is: + // + // List[Container[String] with Template[Container[Any] with Template[Container[Any] with Template[Any]]] + // + + /** Working version explicitly typed. + */ + def fExplicit = List[Template[Container] with Container[String]](new C1[String], new C2[String]) + + // nope + // def fFail = List(new C1[String], new C2[String]) +} -- cgit v1.2.3