Skip to content

Commit eac33f0

Browse files
committed
Make compareHK work if other side is already a lambda.
There ws a missing case, where a lambda projection `T#Apply` is compared to something to a type lambda. In that case we should compare the prefix `T` directly wiht the type lambda. With that modification i553 works if the canBuildFrom implicit is imported. But the implicit is not yet found in the type scope.
1 parent fc5cd47 commit eac33f0

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,23 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
467467
}
468468

469469
/** If `projection` is of the form T # Apply where `T` is an instance of a Lambda class,
470-
* and `other` is not a type lambda projection, then convert `other` to a type lambda `U`, and
471-
* continue with `T <:< U` if `inOrder` is true and `U <:< T` otherwise.
470+
* then
471+
* (1) if `other` is not a (possibly projected) type lambda, convert `other` to a type lambda `U`,
472+
* and continue with `T <:< U` if `inOrder` is true and `U <:< T` otherwise.
473+
* (2) if `other` is a already a type lambda,
474+
* continue with `T <:< other` if `inOrder` is true and `other <:< T` otherwise.
472475
*/
473476
def compareHK(projection: NamedType, other: Type, inOrder: Boolean) =
474477
projection.name == tpnme.Apply && {
475478
val lambda = projection.prefix.LambdaClass(forcing = true)
476-
lambda.exists && !other.isLambda &&
477-
other.testLifted(lambda.typeParams,
478-
if (inOrder) isSubType(projection.prefix, _) else isSubType(_, projection.prefix),
479-
if (inOrder) Nil else classBounds(projection.prefix))
479+
lambda.exists && {
480+
if (!other.isLambda)
481+
other.testLifted(lambda.typeParams,
482+
if (inOrder) isSubType(projection.prefix, _) else isSubType(_, projection.prefix),
483+
if (inOrder) Nil else classBounds(projection.prefix))
484+
else if (inOrder) isSubType(projection.prefix, other)
485+
else isSubType(other, projection.prefix)
486+
}
480487
}
481488

482489
/** The class symbols bounding the type of the `Apply` member of `tp` */

tests/pos/i553-shuffle.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.util.Random
2+
import scala.collection.immutable.List._
3+
object Test {
4+
def test = {
5+
val rand = new Random
6+
rand.shuffle(List(1,2))//(List.canBuildFrom[Int]) // fails
7+
}
8+
}

0 commit comments

Comments
 (0)