Skip to content

Commit 2410651

Browse files
committed
Freeze constraints when checking parameter matching and subsumption.
Checking whether two alternatives are the same should not unify them by instantiating type variables.
1 parent 2d6d432 commit 2410651

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ trait ConstraintHandling {
2323
implicit val ctx: Context
2424

2525
protected def isSubType(tp1: Type, tp2: Type): Boolean
26+
protected def isSameType(tp1: Type, tp2: Type): Boolean
2627

2728
val state: TyperState
2829
import state.constraint
@@ -111,6 +112,13 @@ trait ConstraintHandling {
111112
finally frozenConstraint = saved
112113
}
113114

115+
final def isSameTypeWhenFrozen(tp1: Type, tp2: Type): Boolean = {
116+
val saved = frozenConstraint
117+
frozenConstraint = true
118+
try isSameType(tp1, tp2)
119+
finally frozenConstraint = saved
120+
}
121+
114122
/** Test whether the lower bounds of all parameters in this
115123
* constraint are a solution to the constraint.
116124
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
685685
case formal1 :: rest1 =>
686686
formals2 match {
687687
case formal2 :: rest2 =>
688-
(isSameType(formal1, formal2)
688+
(isSameTypeWhenFrozen(formal1, formal2)
689689
|| isJava1 && (formal2 isRef ObjectClass) && (formal1 isRef AnyClass)
690690
|| isJava2 && (formal1 isRef ObjectClass) && (formal2 isRef AnyClass)) &&
691691
matchingParams(rest1, rest2, isJava1, isJava2)
@@ -1059,7 +1059,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10591059
case tp1: ClassInfo =>
10601060
tp2 match {
10611061
case tp2: ClassInfo =>
1062-
isSubType(tp1.prefix, tp2.prefix) || (tp1.cls.owner derivesFrom tp2.cls.owner)
1062+
isSubTypeWhenFrozen(tp1.prefix, tp2.prefix) || (tp1.cls.owner derivesFrom tp2.cls.owner)
10631063
case _ =>
10641064
false
10651065
}
@@ -1075,7 +1075,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10751075
tp2 match {
10761076
case tp2: MethodType =>
10771077
def asGoodParams(formals1: List[Type], formals2: List[Type]) =
1078-
(formals2 corresponds formals1)(isSubType)
1078+
(formals2 corresponds formals1)(isSubTypeWhenFrozen)
10791079
asGoodParams(tp1.paramTypes, tp2.paramTypes) &&
10801080
(!asGoodParams(tp2.paramTypes, tp1.paramTypes) ||
10811081
isAsGood(tp1.resultType, tp2.resultType))

0 commit comments

Comments
 (0)