diff options
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Inferencing.scala | 9 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 92f65c1fe..d281af733 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1729,7 +1729,7 @@ object Types { * is also a singleton type. */ def instantiate(fromBelow: Boolean)(implicit ctx: Context): Type = { - val upperBound = ctx.typerState.constraint.bounds(origin).hi + def upperBound = ctx.typerState.constraint.bounds(origin).hi def isSingleton(tp: Type): Boolean = tp match { case tp: SingletonType => true case AndType(tp1, tp2) => isSingleton(tp1) | isSingleton(tp2) diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala index fd11e71f2..fbc604db9 100644 --- a/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/src/dotty/tools/dotc/typer/Inferencing.scala @@ -265,10 +265,15 @@ object Inferencing { case _: WildcardType => false case tvar: TypeVar if !tvar.isInstantiated => + def isBottomType(tp: Type) = tp == defn.NothingType || tp == defn.NullType force != ForceDegree.none && { - val inst = tvar.instantiate(fromBelow = !isContravariant(tvar)) + val forceUp = + isContravariant(tvar) || + force == ForceDegree.noBottom && + isBottomType(ctx.typeComparer.approximation(tvar.origin, fromBelow = true)) + val inst = tvar.instantiate(fromBelow = !forceUp) typr.println(i"forced instantiation of ${tvar.origin} = $inst") - (force == ForceDegree.all || inst != defn.NothingType && inst != defn.NullType) && traverse(inst) + traverse(inst) } case _ => true |