diff options
author | Martin Odersky <odersky@gmail.com> | 2015-01-18 18:45:03 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-01-18 18:45:03 +0100 |
commit | 952aa7f8d17579d3ee1b20ea177206e570de497f (patch) | |
tree | 7ee67796df32fb3bda7642c63ffb8ffbead96e25 /src/dotty/tools/dotc/core/TypeComparer.scala | |
parent | 179a1bbd2bb40d1c40823d1d3a1f30f8ecdf5c56 (diff) | |
download | dotty-952aa7f8d17579d3ee1b20ea177206e570de497f.tar.gz dotty-952aa7f8d17579d3ee1b20ea177206e570de497f.tar.bz2 dotty-952aa7f8d17579d3ee1b20ea177206e570de497f.zip |
Avoid adding constraint under typeVarsMissContext is true
SubType check is true anyway, no need to spend work. Also this allows a more
consistent treatment of bounded wildcard types in addConstraint and isSubType. In both cases
we now compare with the outer bound of the wildcard type. Previously addConstraint treated
boundes wildcard types like unbounded ones, which is not consistent.
Diffstat (limited to 'src/dotty/tools/dotc/core/TypeComparer.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 046424eaf..faeef559c 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -183,9 +183,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi tp2 == tp1 || { if (solvedConstraint && (constraint contains tp2)) isSubType(tp1, bounds(tp2).lo) else + (ctx.mode is Mode.TypevarsMissContext) || constraintImpliesSuper(tp2, tp1) || { if (canConstrain(tp2)) addConstraint(tp2, tp1.widenExpr, fromBelow = true) - else (ctx.mode is Mode.TypevarsMissContext) || secondTry(tp1, tp2) + else secondTry(tp1, tp2) } } comparePolyParam @@ -241,23 +242,24 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi case OrType(tp11, tp12) => isSubType(tp11, tp2) && isSubType(tp12, tp2) case tp1: PolyParam => + def flagNothingBound = { + if ((!frozenConstraint) && + (tp2 isRef defn.NothingClass) && + state.isGlobalCommittable) { + def msg = s"!!! instantiated to Nothing: $tp1, constraint = ${constraint.show}" + if (Config.flagInstantiationToNothing) assert(false, msg) + else ctx.log(msg) + } + true + } def comparePolyParam = tp1 == tp2 || { if (solvedConstraint && (constraint contains tp1)) isSubType(bounds(tp1).lo, tp2) else + (ctx.mode is Mode.TypevarsMissContext) || constraintImpliesSub(tp1, tp2) || { - if (canConstrain(tp1)) - addConstraint(tp1, tp2, fromBelow = false) && { - if ((!frozenConstraint) && - (tp2 isRef defn.NothingClass) && - state.isGlobalCommittable) { - def msg = s"!!! instantiated to Nothing: $tp1, constraint = ${constraint.show}" - if (Config.flagInstantiationToNothing) assert(false, msg) - else ctx.log(msg) - } - true - } - else (ctx.mode is Mode.TypevarsMissContext) || thirdTry(tp1, tp2) + if (canConstrain(tp1)) addConstraint(tp1, tp2, fromBelow = false) && flagNothingBound + else thirdTry(tp1, tp2) } } comparePolyParam |