Skip to content

Commit ce87f2a

Browse files
committed
Fix #3213: Make PolyTypes generative
Because PolyTypes are used as carriers of constrained parameter references, we must make sure that we can duplicate them so that the duplicate is different from the original. Hence, it's useless to cache PolyTypes.
1 parent 7d12c39 commit ce87f2a

File tree

1 file changed

+29
-54
lines changed

1 file changed

+29
-54
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,57 +2599,8 @@ object Types {
25992599
final override def toString = s"$prefixString($paramNames, $paramInfos, $resType)"
26002600
}
26012601

2602-
abstract class HKLambda extends CachedProxyType with LambdaType {
2603-
final override def underlying(implicit ctx: Context) = resType
2604-
2605-
final override def computeHash = doHash(paramNames, resType, paramInfos)
2606-
2607-
// Defined here instead of in LambdaType for efficiency
2608-
final override def equals(that: Any) = that match {
2609-
case that: HKLambda =>
2610-
paramNames == that.paramNames &&
2611-
paramInfos == that.paramInfos &&
2612-
resType == that.resType &&
2613-
companion.eq(that.companion)
2614-
case _ =>
2615-
false
2616-
}
2617-
2618-
final override def eql(that: Type) = that match {
2619-
case that: HKLambda =>
2620-
paramNames.equals(that.paramNames) &&
2621-
paramInfos.equals(that.paramInfos) &&
2622-
resType.equals(that.resType) &&
2623-
companion.eq(that.companion)
2624-
case _ =>
2625-
false
2626-
}
2627-
}
2628-
2629-
abstract class MethodOrPoly extends CachedGroundType with LambdaType with MethodicType {
2630-
final override def computeHash = doHash(paramNames, resType, paramInfos)
2631-
2632-
// Defined here instead of in LambdaType for efficiency
2633-
final override def equals(that: Any) = that match {
2634-
case that: MethodOrPoly =>
2635-
paramNames == that.paramNames &&
2636-
paramInfos == that.paramInfos &&
2637-
resType == that.resType &&
2638-
companion.eq(that.companion)
2639-
case _ =>
2640-
false
2641-
}
2642-
2643-
final override def eql(that: Type) = that match {
2644-
case that: MethodOrPoly =>
2645-
paramNames.eqElements(that.paramNames) &&
2646-
paramInfos.eqElements(that.paramInfos) &&
2647-
resType.eq(that.resType) &&
2648-
companion.eq(that.companion)
2649-
case _ =>
2650-
false
2651-
}
2652-
}
2602+
trait HKLambda extends LambdaType
2603+
trait MethodOrPoly extends LambdaType with MethodicType
26532604

26542605
trait TermLambda extends LambdaType { thisLambdaType =>
26552606
import DepStatus._
@@ -2752,7 +2703,7 @@ object Types {
27522703
abstract case class MethodType(paramNames: List[TermName])(
27532704
paramInfosExp: MethodType => List[Type],
27542705
resultTypeExp: MethodType => Type)
2755-
extends MethodOrPoly with TermLambda with NarrowCached { thisMethodType =>
2706+
extends CachedGroundType with MethodOrPoly with TermLambda with NarrowCached { thisMethodType =>
27562707
import MethodType._
27572708

27582709
type This = MethodType
@@ -2764,6 +2715,28 @@ object Types {
27642715
def computeSignature(implicit ctx: Context): Signature =
27652716
resultSignature.prepend(paramInfos, isJava)
27662717

2718+
final override def computeHash = doHash(paramNames, resType, paramInfos)
2719+
2720+
final override def equals(that: Any) = that match {
2721+
case that: MethodType =>
2722+
paramNames == that.paramNames &&
2723+
paramInfos == that.paramInfos &&
2724+
resType == that.resType &&
2725+
companion.eq(that.companion)
2726+
case _ =>
2727+
false
2728+
}
2729+
2730+
final override def eql(that: Type) = that match {
2731+
case that: MethodType =>
2732+
paramNames.eqElements(that.paramNames) &&
2733+
paramInfos.eqElements(that.paramInfos) &&
2734+
resType.eq(that.resType) &&
2735+
companion.eq(that.companion)
2736+
case _ =>
2737+
false
2738+
}
2739+
27672740
protected def prefixString = "MethodType"
27682741
}
27692742

@@ -2936,7 +2909,7 @@ object Types {
29362909
*/
29372910
class HKTypeLambda(val paramNames: List[TypeName])(
29382911
paramInfosExp: HKTypeLambda => List[TypeBounds], resultTypeExp: HKTypeLambda => Type)
2939-
extends HKLambda with TypeLambda {
2912+
extends UncachedProxyType with HKLambda with TypeLambda {
29402913
type This = HKTypeLambda
29412914
def companion = HKTypeLambda
29422915

@@ -2946,6 +2919,8 @@ object Types {
29462919
assert(resType.isInstanceOf[TermType], this)
29472920
assert(paramNames.nonEmpty)
29482921

2922+
final override def underlying(implicit ctx: Context) = resType
2923+
29492924
protected def prefixString = "HKTypeLambda"
29502925
}
29512926

@@ -2954,7 +2929,7 @@ object Types {
29542929
*/
29552930
class PolyType(val paramNames: List[TypeName])(
29562931
paramInfosExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type)
2957-
extends MethodOrPoly with TypeLambda {
2932+
extends UncachedGroundType with MethodOrPoly with TypeLambda {
29582933

29592934
type This = PolyType
29602935
def companion = PolyType

0 commit comments

Comments
 (0)