Skip to content

Commit 419d232

Browse files
committed
Don't interpolate downwards to a bottom type
If the result of a covariant type variable interpolation would be a bottom type, wait instead. This could make the variable be inferred to its upper bound after all, if we do not need a fully instantiated type right away.
1 parent 78d043a commit 419d232

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,14 @@ trait Inferencing { this: Typer =>
433433
else if (!hasUnreportedErrors)
434434
if (v.intValue != 0) {
435435
typr.println(i"interpolate $tvar in $state in $tree: $tp, fromBelow = ${v.intValue == 1}, $constraint")
436-
tvar.instantiate(fromBelow = v.intValue == 1)
436+
if (true) {
437+
val fromBelow = v.intValue == 1
438+
val instType = ctx.typeComparer.instanceType(tvar.origin, fromBelow)
439+
if (!(fromBelow && instType.isRef(defn.NothingClass)))
440+
tvar.instantiateWith(instType)
441+
}
442+
else
443+
tvar.instantiate(fromBelow = v.intValue == 1)
437444
}
438445
else typr.println(i"no interpolation for nonvariant $tvar in $state")
439446
}
File renamed without changes.

tests/run/type-propagation.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test extends App {
2+
def foo: String = {
3+
"abc".asInstanceOf
4+
}
5+
6+
assert(foo == "abc")
7+
}

0 commit comments

Comments
 (0)