Skip to content

Commit 34a2b96

Browse files
committed
Harden constraint handling in IDE
I observed assertion failures, that a param ref is not in the current constraint. Avoiding an assertion failure if that case is encountered in the IDE.
1 parent af0336a commit 34a2b96

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,16 @@ trait ConstraintHandling {
222222
}
223223
}
224224
}
225-
assert(constraint.contains(param))
226-
val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param)
227-
val inst = avoidParam(bound)
228-
typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
229-
inst
225+
if (constraint.contains(param)) {
226+
val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param)
227+
val inst = avoidParam(bound)
228+
typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
229+
inst
230+
}
231+
else {
232+
assert(ctx.mode.is(Mode.Interactive))
233+
UnspecifiedErrorType
234+
}
230235
}
231236

232237
/** The instance type of `param` in the current constraint (which contains `param`).

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

-1
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,6 @@ object Types {
31943194
private def instantiateWith(tp: Type)(implicit ctx: Context): Type = {
31953195
assert(tp ne this, s"self instantiation of ${tp.show}, constraint = ${ctx.typerState.constraint.show}")
31963196
typr.println(s"instantiating ${this.show} with ${tp.show}")
3197-
assert(ctx.typerState.constraint contains this) // !!! DEBUG
31983197
if ((ctx.typerState eq owningState) && !ctx.typeComparer.subtypeCheckInProgress)
31993198
inst = tp
32003199
ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)

0 commit comments

Comments
 (0)