@@ -428,9 +428,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
428428 compareRec
429429 case tp2 @ HKApply (tycon2, args2) =>
430430 compareHkApply2(tp1, tp2, tycon2, args2)
431- case tp2 : TypeLambda =>
431+ case tp2 : HKTypeLambda =>
432432 def compareTypeLambda : Boolean = tp1.stripTypeVar match {
433- case tp1 : TypeLambda if tp1. isInstanceOf [ PolyType ] == tp2. isInstanceOf [ PolyType ] =>
433+ case tp1 : TypeLambda =>
434434 /* Don't compare bounds of lambdas under language:Scala2, or t2994 will fail
435435 * The issue is that, logically, bounds should compare contravariantly,
436436 * but that would invalidate a pattern exploited in t2994:
@@ -484,12 +484,12 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
484484 case _ =>
485485 }
486486 either(isSubType(tp1, tp21), isSubType(tp1, tp22)) || fourthTry(tp1, tp2)
487- case tp2 : MethodType =>
487+ case tp2 : MethodOrPoly =>
488488 def compareMethod = tp1 match {
489- case tp1 : MethodType =>
489+ case tp1 : MethodOrPoly =>
490490 (tp1.signature consistentParams tp2.signature) &&
491- matchingParams(tp1.paramInfos , tp2.paramInfos, tp1.isJava, tp2.isJava ) &&
492- ( tp1.isImplicit == tp2.isImplicit) &&
491+ matchingParams(tp1, tp2) &&
492+ tp1.isImplicit == tp2.isImplicit &&
493493 isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
494494 case _ =>
495495 false
@@ -1021,7 +1021,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10211021 tp2.widen match {
10221022 case tp2 : MethodType =>
10231023 // implicitness is ignored when matching
1024- matchingParams(tp1.paramInfos , tp2.paramInfos, tp1.isJava, tp2.isJava ) &&
1024+ matchingParams(tp1, tp2) &&
10251025 matchesType(tp1.resultType, tp2.resultType.subst(tp2, tp1), relaxed)
10261026 case tp2 =>
10271027 relaxed && tp1.paramNames.isEmpty &&
@@ -1031,7 +1031,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10311031 tp2.widen match {
10321032 case tp2 : PolyType =>
10331033 sameLength(tp1.paramNames, tp2.paramNames) &&
1034- matchesType(tp1.resultType, tp2.resultType.subst(tp2, tp1), relaxed)
1034+ matchesType(tp1.resultType, tp2.resultType.subst(tp2, tp1), relaxed)
10351035 case _ =>
10361036 false
10371037 }
@@ -1047,28 +1047,28 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10471047 }
10481048 }
10491049
1050- /** Are `syms1` and `syms2` parameter lists with pairwise equivalent types? */
1051- def matchingParams (formals1 : List [Type ], formals2 : List [Type ], isJava1 : Boolean , isJava2 : Boolean ): Boolean = formals1 match {
1052- case formal1 :: rest1 =>
1053- formals2 match {
1054- case formal2 :: rest2 =>
1055- (isSameTypeWhenFrozen(formal1, formal2)
1056- || isJava1 && (formal2 isRef ObjectClass ) && (formal1 isRef AnyClass )
1057- || isJava2 && (formal1 isRef ObjectClass ) && (formal2 isRef AnyClass )) &&
1058- matchingParams(rest1, rest2, isJava1, isJava2)
1059- case nil =>
1060- false
1061- }
1062- case nil =>
1063- formals2.isEmpty
1064- }
1065-
1066- /** Do generic types `poly1` and `poly2` have type parameters that
1067- * have the same bounds (after renaming one set to the other)?
1050+ /** Do lambda types `lam1` and `lam2` have parameters that have the same types
1051+ * and the same implicit status? (after renaming one set to the other)
10681052 */
1069- def matchingTypeParams (poly1 : PolyType , poly2 : PolyType ): Boolean =
1070- (poly1.paramInfos corresponds poly2.paramInfos)((b1, b2) =>
1071- isSameType(b1, b2.subst(poly2, poly1)))
1053+ def matchingParams (lam1 : MethodOrPoly , lam2 : MethodOrPoly ): Boolean = {
1054+ /** Are `syms1` and `syms2` parameter lists with pairwise equivalent types? */
1055+ def loop (formals1 : List [Type ], formals2 : List [Type ]): Boolean = formals1 match {
1056+ case formal1 :: rest1 =>
1057+ formals2 match {
1058+ case formal2 :: rest2 =>
1059+ val formal2a = if (lam2.isParamDependent) formal2.subst(lam2, lam1) else formal2
1060+ (isSameTypeWhenFrozen(formal1, formal2a)
1061+ || lam1.isJava && (formal2 isRef ObjectClass ) && (formal1 isRef AnyClass )
1062+ || lam2.isJava && (formal1 isRef ObjectClass ) && (formal2 isRef AnyClass )) &&
1063+ loop(rest1, rest2)
1064+ case nil =>
1065+ false
1066+ }
1067+ case nil =>
1068+ formals2.isEmpty
1069+ }
1070+ loop(lam1.paramInfos, lam2.paramInfos)
1071+ }
10721072
10731073 // Type equality =:=
10741074
@@ -1281,7 +1281,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12811281 original(tp1.appliedTo(tp1.typeParams.map(_.paramInfoAsSeenFrom(tp1))), tp2)
12821282 else
12831283 HKTypeLambda (
1284- paramNames = (tpnme.syntheticTypeParamNames (tparams1.length), tparams1, tparams2)
1284+ paramNames = (HKTypeLambda .syntheticParamNames (tparams1.length), tparams1, tparams2)
12851285 .zipped.map((pname, tparam1, tparam2) =>
12861286 pname.withVariance((tparam1.paramVariance + tparam2.paramVariance) / 2 )))(
12871287 paramInfosExp = tl => (tparams1, tparams2).zipped.map((tparam1, tparam2) =>
0 commit comments