Skip to content

Don't interpolate downwards to Nothing #7130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,14 @@ trait Inferencing { this: Typer =>
else if (!hasUnreportedErrors)
if (v.intValue != 0) {
typr.println(i"interpolate $tvar in $state in $tree: $tp, fromBelow = ${v.intValue == 1}, $constraint")
tvar.instantiate(fromBelow = v.intValue == 1)
if (true) {
val fromBelow = v.intValue == 1
val instType = ctx.typeComparer.instanceType(tvar.origin, fromBelow)
if (!(fromBelow && instType.isRef(defn.NothingClass)))
tvar.instantiateWith(instType)
}
else
tvar.instantiate(fromBelow = v.intValue == 1)
}
else typr.println(i"no interpolation for nonvariant $tvar in $state")
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/i536.scala → tests/neg/i536.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ object Max {
val m1 = max(xs)
val m2 = max(null)

java.util.Collections.max(null)
java.util.Collections.max(null) // error: Type argument Comparable[_] does not conform to upper bound Comparable[_ >: LazyRef(Comparable[_])]
}
File renamed without changes.
7 changes: 7 additions & 0 deletions tests/run/type-propagation.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test extends App {
def foo: String = {
"abc".asInstanceOf
}

assert(foo == "abc")
}