From acc4c04b0c29436d2328d0e31a26bf2be4b96117 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 13 Sep 2011 17:50:46 +0000 Subject: Refine lub calculation. When a reasonable lub cannot be arrived at by direct means, use the bounds of the lub inputs to derive bounds for the lub rather than giving up. Closes SI-4938, review by moors. --- src/compiler/scala/reflect/internal/Types.scala | 12 ++++++++++-- test/files/pos/t4938.scala | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/files/pos/t4938.scala diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index a6b1e2fb44..9683087a95 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -5822,10 +5822,18 @@ A type's typeSymbol should never be inspected directly. } } else { val args = (sym.typeParams, argss.transpose).zipped map { (tparam, as) => - if (depth == 0) - if (tparam.variance == variance) AnyClass.tpe + if (depth == 0) { + if (tparam.variance == variance) { + // Take the intersection of the upper bounds of the type parameters + // rather than falling all the way back to "Any", otherwise we end up not + // conforming to bounds. + val bounds0 = sym.typeParams map (_.info.bounds.hi) filterNot (_.typeSymbol == AnyClass) + if (bounds0.isEmpty) AnyClass.tpe + else intersectionType(bounds0) + } else if (tparam.variance == -variance) NothingClass.tpe else NoType + } else { if (tparam.variance == variance) lub(as, decr(depth)) else if (tparam.variance == -variance) glb(as, decr(depth)) diff --git a/test/files/pos/t4938.scala b/test/files/pos/t4938.scala new file mode 100644 index 0000000000..6e41312851 --- /dev/null +++ b/test/files/pos/t4938.scala @@ -0,0 +1,4 @@ +class A { + import scala.collection.mutable._ + val xs = List(Set(), Seq()) +} -- cgit v1.2.3