@@ -1394,16 +1394,21 @@ object Types {
1394
1394
*/
1395
1395
def simplified (implicit ctx : Context ) = ctx.simplify(this , null )
1396
1396
1397
+ /** Compare `this == that`, assuming corresponding binders in `bs` are equal.
1398
+ * The normal `equals` should be equivalent to `equals(that, null`)`.
1399
+ * We usually override `equals` when we override `iso` except if the
1400
+ * `equals` comes from a case class, so it already has the right definition anyway.
1401
+ */
1397
1402
final def equals (that : Any , bs : BinderPairs ): Boolean =
1398
1403
(this `eq` that.asInstanceOf [AnyRef ]) || this .iso(that, bs)
1399
1404
1400
- /** Is `this` isomorphic to that, using comparer `e `?
1405
+ /** Is `this` isomorphic to ` that`, assuming pairs of matching binders `bs `?
1401
1406
* It is assumed that `this.ne(that)`.
1402
1407
*/
1403
1408
protected def iso (that : Any , bs : BinderPairs ): Boolean = this .equals(that)
1404
1409
1405
1410
/** Equality used for hash-consing; uses `eq` on all recursive invocations,
1406
- * except where a BindingType is inloved . The latter demand a deep isomorphism check.
1411
+ * except where a BindingType is involved . The latter demand a deep isomorphism check.
1407
1412
*/
1408
1413
def eql (that : Type ): Boolean = this .equals(that)
1409
1414
@@ -1531,7 +1536,7 @@ object Types {
1531
1536
* Otherise the standard identity hash.
1532
1537
*/
1533
1538
override def identityHash (bs : Binders ) = {
1534
- def recur (n : Int , tp : BindingType , rest : Binders ): Int =
1539
+ def recur (n : Int , tp : BindingType , rest : Binders ): Int =
1535
1540
if (this `eq` tp) finishHash(hashing.mix(hashSeed, n), 1 )
1536
1541
else if (rest == null ) System .identityHashCode(this )
1537
1542
else recur(n + 1 , rest.tp, rest.next)
@@ -2311,6 +2316,7 @@ object Types {
2311
2316
parent.equals(that.parent, bs)
2312
2317
case _ => false
2313
2318
}
2319
+ // equals comes from case class; no matching override is needed
2314
2320
}
2315
2321
2316
2322
class CachedRefinedType (parent : Type , refinedName : Name , refinedInfo : Type )
@@ -2473,6 +2479,7 @@ object Types {
2473
2479
case that : AndOrType => isAnd == that.isAnd && tp1.equals(that.tp1, bs) && tp2.equals(that.tp2, bs)
2474
2480
case _ => false
2475
2481
}
2482
+ // equals comes from case classes; no matching override is needed
2476
2483
}
2477
2484
2478
2485
abstract case class AndType (tp1 : Type , tp2 : Type ) extends AndOrType {
@@ -2615,6 +2622,7 @@ object Types {
2615
2622
case that : ExprType => resType.equals(that.resType, bs)
2616
2623
case _ => false
2617
2624
}
2625
+ // equals comes from case class; no matching override is needed
2618
2626
}
2619
2627
2620
2628
final class CachedExprType (resultType : Type ) extends ExprType (resultType)
@@ -2718,6 +2726,22 @@ object Types {
2718
2726
abstract class MethodOrPoly extends UncachedGroundType with LambdaType with MethodicType {
2719
2727
final override def hashCode = System .identityHashCode(this )
2720
2728
final override def equals (other : Any ) = this `eq` other.asInstanceOf [AnyRef ]
2729
+
2730
+ final override def equals (that : Any ) = equals(that, null )
2731
+
2732
+ // No definition of `eql` --> fall back on equals, which calls iso
2733
+
2734
+ final override def iso (that : Any , bs : BinderPairs ) = that match {
2735
+ case that : MethodOrPoly =>
2736
+ paramNames.eqElements(that.paramNames) &&
2737
+ companion.eq(that.companion) && {
2738
+ val bs1 = new BinderPairs (this , that, bs)
2739
+ paramInfos.equalElements(that.paramInfos, bs1) &&
2740
+ resType.equals(that.resType, bs1)
2741
+ }
2742
+ case _ =>
2743
+ false
2744
+ }
2721
2745
}
2722
2746
2723
2747
trait TermLambda extends LambdaType { thisLambdaType =>
@@ -3183,6 +3207,7 @@ object Types {
3183
3207
case that : AppliedType => tycon.equals(that.tycon, bs) && args.equalElements(that.args, bs)
3184
3208
case _ => false
3185
3209
}
3210
+ // equals comes from case class; no matching override is needed
3186
3211
}
3187
3212
3188
3213
final class CachedAppliedType (tycon : Type , args : List [Type ], hc : Int ) extends AppliedType (tycon, args) {
@@ -3221,7 +3246,7 @@ object Types {
3221
3246
override def equals (that : Any ) = equals(that, null )
3222
3247
3223
3248
override def iso (that : Any , bs : BinderPairs ) = that match {
3224
- case that : ParamRef => binder.equalBinder(that.binder, bs) && paramNum == that.paramNum
3249
+ case that : ParamRef => paramNum == that.paramNum && binder.equalBinder(that.binder, bs)
3225
3250
case _ => false
3226
3251
}
3227
3252
@@ -3608,6 +3633,7 @@ object Types {
3608
3633
case that : TypeAlias => alias.equals(that.alias, bs)
3609
3634
case _ => false
3610
3635
}
3636
+ // equals comes from case class; no matching override is needed
3611
3637
3612
3638
override def eql (that : Type ): Boolean = that match {
3613
3639
case that : TypeAlias => alias.eq(that.alias)
@@ -3652,6 +3678,7 @@ object Types {
3652
3678
case that : AnnotatedType => tpe.equals(that.tpe, bs) && (annot `eq` that.annot)
3653
3679
case _ => false
3654
3680
}
3681
+ // equals comes from case class; no matching override is needed
3655
3682
}
3656
3683
3657
3684
object AnnotatedType {
@@ -3742,6 +3769,7 @@ object Types {
3742
3769
case that : WildcardType => optBounds.equals(that.optBounds, bs)
3743
3770
case _ => false
3744
3771
}
3772
+ // equals comes from case class; no matching override is needed
3745
3773
}
3746
3774
3747
3775
final class CachedWildcardType (optBounds : Type ) extends WildcardType (optBounds)
0 commit comments