diff options
-rw-r--r-- | src/dotty/tools/dotc/core/Constraint.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TyperState.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 6 |
4 files changed, 13 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/Constraint.scala b/src/dotty/tools/dotc/core/Constraint.scala index 29e1e01fe..d2ea6aa65 100644 --- a/src/dotty/tools/dotc/core/Constraint.scala +++ b/src/dotty/tools/dotc/core/Constraint.scala @@ -19,6 +19,12 @@ class Constraint(val map: SimpleMap[PolyType, Array[Type]]) extends AnyVal with /** Does the constraint's domain contain the type parameters of `pt`? */ def contains(pt: PolyType): Boolean = map(pt) != null + /** Does the constraint's domain contain the type parameter `param`? */ + def contains(param: PolyParam): Boolean = { + val entries = map(param.binder) + entries != null && entries(param.paramNum).exists + } + /** The constraint for given type parameter `param`, or NoType if `param` is not part of * the constraint domain. */ diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index a4d96019e..a796d7e43 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -56,8 +56,9 @@ class TypeComparer(initctx: Context) extends DotClass { val pnum = param.paramNum val oldEntries = constraint(pt) val oldBounds = oldEntries(pnum).asInstanceOf[TypeBounds] - val constrBounds = if (fromBelow) TypeBounds.lower(bound) else TypeBounds.upper(bound) - val newBounds = oldBounds & constrBounds + val newBounds = + if (fromBelow) oldBounds.derivedTypeBounds(oldBounds.lo | bound, oldBounds.hi) + else oldBounds.derivedTypeBounds(oldBounds.lo, oldBounds.hi & bound) if (oldBounds ne newBounds) { val newEntries = oldEntries.clone newEntries(pnum) = newBounds diff --git a/src/dotty/tools/dotc/core/TyperState.scala b/src/dotty/tools/dotc/core/TyperState.scala index 8246ae198..626c1227f 100644 --- a/src/dotty/tools/dotc/core/TyperState.scala +++ b/src/dotty/tools/dotc/core/TyperState.scala @@ -104,7 +104,7 @@ extends TyperState(reporter) { def checkConsistent(show: Showable => String = MutableTyperState.toStr): Unit = if (checkingEnabled) { def err(msg: String, what: Showable) = s"$msg: ${show(what)}\n${show(this)}" for (tvar <- undetVars) - assert(constraint(tvar.origin).exists, err("unconstrained type var", tvar.origin)) + assert(constraint contains tvar.origin, err("unconstrained type var", tvar.origin)) if (isCommittable) { val undetParams = undetVars map (_.origin) for (param <- constraint.domainParams) diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 9d6df553c..f1b603b4a 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -598,9 +598,9 @@ trait Applications extends Compatibility { self: Typer => ctx.maximizeType(unapplyArgType) match { case Some(tvar) => def msg = - s"""There is no best instantiation of pattern type ${unapplyArgType.show} - |that makes it a subtype of selector type ${pt.show}. - |Non-variant type variable ${tvar.origin.show} cannot be uniquely instantiated.""".stripMargin + i"""There is no best instantiation of pattern type $unapplyArgType + |that makes it a subtype of selector type $pt. + |Non-variant type variable ${tvar.origin} cannot be uniquely instantiated.""".stripMargin if (fromScala2x) { // We can't issue an error here, because in Scala 2, ::[B] is invariant // whereas List[+T] is covariant. According to the strict rule, a pattern |