@@ -1399,16 +1399,21 @@ object Types {
1399
1399
*/
1400
1400
def simplified (implicit ctx : Context ) = ctx.simplify(this , null )
1401
1401
1402
+ /** Compare `this == that`, assuming corresponding binders in `bs` are equal.
1403
+ * The normal `equals` should be equivalent to `equals(that, null`)`.
1404
+ * We usually override `equals` when we override `iso` except if the
1405
+ * `equals` comes from a case class, so it already has the right definition anyway.
1406
+ */
1402
1407
final def equals (that : Any , bs : BinderPairs ): Boolean =
1403
1408
(this `eq` that.asInstanceOf [AnyRef ]) || this .iso(that, bs)
1404
1409
1405
- /** Is `this` isomorphic to that, using comparer `e `?
1410
+ /** Is `this` isomorphic to ` that`, assuming pairs of matching binders `bs `?
1406
1411
* It is assumed that `this.ne(that)`.
1407
1412
*/
1408
1413
protected def iso (that : Any , bs : BinderPairs ): Boolean = this .equals(that)
1409
1414
1410
1415
/** Equality used for hash-consing; uses `eq` on all recursive invocations,
1411
- * except where a BindingType is inloved . The latter demand a deep isomorphism check.
1416
+ * except where a BindingType is involved . The latter demand a deep isomorphism check.
1412
1417
*/
1413
1418
def eql (that : Type ): Boolean = this .equals(that)
1414
1419
@@ -1536,7 +1541,7 @@ object Types {
1536
1541
* Otherise the standard identity hash.
1537
1542
*/
1538
1543
override def identityHash (bs : Binders ) = {
1539
- def recur (n : Int , tp : BindingType , rest : Binders ): Int =
1544
+ def recur (n : Int , tp : BindingType , rest : Binders ): Int =
1540
1545
if (this `eq` tp) finishHash(hashing.mix(hashSeed, n), 1 )
1541
1546
else if (rest == null ) System .identityHashCode(this )
1542
1547
else recur(n + 1 , rest.tp, rest.next)
@@ -2320,6 +2325,7 @@ object Types {
2320
2325
parent.equals(that.parent, bs)
2321
2326
case _ => false
2322
2327
}
2328
+ // equals comes from case class; no matching override is needed
2323
2329
}
2324
2330
2325
2331
class CachedRefinedType (parent : Type , refinedName : Name , refinedInfo : Type )
@@ -2482,6 +2488,7 @@ object Types {
2482
2488
case that : AndOrType => isAnd == that.isAnd && tp1.equals(that.tp1, bs) && tp2.equals(that.tp2, bs)
2483
2489
case _ => false
2484
2490
}
2491
+ // equals comes from case classes; no matching override is needed
2485
2492
}
2486
2493
2487
2494
abstract case class AndType (tp1 : Type , tp2 : Type ) extends AndOrType {
@@ -2624,6 +2631,7 @@ object Types {
2624
2631
case that : ExprType => resType.equals(that.resType, bs)
2625
2632
case _ => false
2626
2633
}
2634
+ // equals comes from case class; no matching override is needed
2627
2635
}
2628
2636
2629
2637
final class CachedExprType (resultType : Type ) extends ExprType (resultType)
@@ -2727,6 +2735,22 @@ object Types {
2727
2735
abstract class MethodOrPoly extends UncachedGroundType with LambdaType with MethodicType {
2728
2736
final override def hashCode = System .identityHashCode(this )
2729
2737
final override def equals (other : Any ) = this `eq` other.asInstanceOf [AnyRef ]
2738
+
2739
+ final override def equals (that : Any ) = equals(that, null )
2740
+
2741
+ // No definition of `eql` --> fall back on equals, which calls iso
2742
+
2743
+ final override def iso (that : Any , bs : BinderPairs ) = that match {
2744
+ case that : MethodOrPoly =>
2745
+ paramNames.eqElements(that.paramNames) &&
2746
+ companion.eq(that.companion) && {
2747
+ val bs1 = new BinderPairs (this , that, bs)
2748
+ paramInfos.equalElements(that.paramInfos, bs1) &&
2749
+ resType.equals(that.resType, bs1)
2750
+ }
2751
+ case _ =>
2752
+ false
2753
+ }
2730
2754
}
2731
2755
2732
2756
trait TermLambda extends LambdaType { thisLambdaType =>
@@ -3192,6 +3216,7 @@ object Types {
3192
3216
case that : AppliedType => tycon.equals(that.tycon, bs) && args.equalElements(that.args, bs)
3193
3217
case _ => false
3194
3218
}
3219
+ // equals comes from case class; no matching override is needed
3195
3220
}
3196
3221
3197
3222
final class CachedAppliedType (tycon : Type , args : List [Type ], hc : Int ) extends AppliedType (tycon, args) {
@@ -3230,7 +3255,7 @@ object Types {
3230
3255
override def equals (that : Any ) = equals(that, null )
3231
3256
3232
3257
override def iso (that : Any , bs : BinderPairs ) = that match {
3233
- case that : ParamRef => binder.equalBinder(that.binder, bs) && paramNum == that.paramNum
3258
+ case that : ParamRef => paramNum == that.paramNum && binder.equalBinder(that.binder, bs)
3234
3259
case _ => false
3235
3260
}
3236
3261
@@ -3617,6 +3642,7 @@ object Types {
3617
3642
case that : TypeAlias => alias.equals(that.alias, bs)
3618
3643
case _ => false
3619
3644
}
3645
+ // equals comes from case class; no matching override is needed
3620
3646
3621
3647
override def eql (that : Type ): Boolean = that match {
3622
3648
case that : TypeAlias => alias.eq(that.alias)
@@ -3661,6 +3687,7 @@ object Types {
3661
3687
case that : AnnotatedType => tpe.equals(that.tpe, bs) && (annot `eq` that.annot)
3662
3688
case _ => false
3663
3689
}
3690
+ // equals comes from case class; no matching override is needed
3664
3691
}
3665
3692
3666
3693
object AnnotatedType {
@@ -3751,6 +3778,7 @@ object Types {
3751
3778
case that : WildcardType => optBounds.equals(that.optBounds, bs)
3752
3779
case _ => false
3753
3780
}
3781
+ // equals comes from case class; no matching override is needed
3754
3782
}
3755
3783
3756
3784
final class CachedWildcardType (optBounds : Type ) extends WildcardType (optBounds)
0 commit comments