diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index fba306b49fe0..4ee932477887 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -227,15 +227,15 @@ trait ConstraintHandling { } } } - if (constraint.contains(param)) { - val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param) - val inst = avoidParam(bound) - typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}") - inst - } - else { - assert(ctx.mode.is(Mode.Interactive)) - UnspecifiedErrorType + constraint.entry(param) match { + case _: TypeBounds => + val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param) + val inst = avoidParam(bound) + typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}") + inst + case inst => + assert(inst.exists, i"param = $param\n constraint = $constraint") + inst } } diff --git a/tests/neg/i2979.scala b/tests/neg/i2979.scala new file mode 100644 index 000000000000..8cb62f10ae93 --- /dev/null +++ b/tests/neg/i2979.scala @@ -0,0 +1,6 @@ +object Main { + Map( + "a" -> Unknown(), // error + "b" -> Unknown() // error + ) +}