Skip to content

Commit acc4c04

Browse files
committed
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.
1 parent 3949410 commit acc4c04

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/compiler/scala/reflect/internal/Types.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5822,10 +5822,18 @@ A type's typeSymbol should never be inspected directly.
58225822
}
58235823
} else {
58245824
val args = (sym.typeParams, argss.transpose).zipped map { (tparam, as) =>
5825-
if (depth == 0)
5826-
if (tparam.variance == variance) AnyClass.tpe
5825+
if (depth == 0) {
5826+
if (tparam.variance == variance) {
5827+
// Take the intersection of the upper bounds of the type parameters
5828+
// rather than falling all the way back to "Any", otherwise we end up not
5829+
// conforming to bounds.
5830+
val bounds0 = sym.typeParams map (_.info.bounds.hi) filterNot (_.typeSymbol == AnyClass)
5831+
if (bounds0.isEmpty) AnyClass.tpe
5832+
else intersectionType(bounds0)
5833+
}
58275834
else if (tparam.variance == -variance) NothingClass.tpe
58285835
else NoType
5836+
}
58295837
else {
58305838
if (tparam.variance == variance) lub(as, decr(depth))
58315839
else if (tparam.variance == -variance) glb(as, decr(depth))

test/files/pos/t4938.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class A {
2+
import scala.collection.mutable._
3+
val xs = List(Set(), Seq())
4+
}

0 commit comments

Comments
 (0)