summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-09-13 17:50:46 +0000
committerPaul Phillips <paulp@improving.org>2011-09-13 17:50:46 +0000
commitacc4c04b0c29436d2328d0e31a26bf2be4b96117 (patch)
treecc86c5aef30ddc2257f4ac09a157c2c89fe8ca90
parent3949410af713249a8d2c8a494eb2b6711a0805a0 (diff)
downloadscala-acc4c04b0c29436d2328d0e31a26bf2be4b96117.tar.gz
scala-acc4c04b0c29436d2328d0e31a26bf2be4b96117.tar.bz2
scala-acc4c04b0c29436d2328d0e31a26bf2be4b96117.zip
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.
-rw-r--r--src/compiler/scala/reflect/internal/Types.scala12
-rw-r--r--test/files/pos/t4938.scala4
2 files changed, 14 insertions, 2 deletions
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())
+}