From 41791ab430b89ef256dcb749176f95e521524370 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 14 Jan 2018 02:37:08 +0100 Subject: [PATCH] Fix #2979: Allow for instantiated params when approximating When approximating, some of the type parameters might already be instantiated by earlier interpolations. --- .../tools/dotc/core/ConstraintHandling.scala | 18 +++++++++--------- tests/neg/i2979.scala | 6 ++++++ 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 tests/neg/i2979.scala 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 + ) +}