Skip to content
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

Teach provablyDisjoint to handle FromJavaObject #15769

Merged
merged 1 commit into from
Jul 29, 2022
Merged
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
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2597,6 +2597,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
}.apply(true, tp)

(tp1.dealias, tp2.dealias) match {
case _ if !ctx.erasedTypes && tp2.isFromJavaObject =>
provablyDisjoint(tp1, defn.AnyType)
case _ if !ctx.erasedTypes && tp1.isFromJavaObject =>
provablyDisjoint(defn.AnyType, tp2)
case (tp1: TypeRef, _) if tp1.symbol == defn.SingletonClass =>
false
case (_, tp2: TypeRef) if tp2.symbol == defn.SingletonClass =>
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/i15717.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// scalac: -Werror
class Test:
def pmat(xs: java.util.Vector[_]): String = xs.get(0) match
case d: Double => d.toString() // was: error: unreachable case, which is spurious
case _ => "shrug"

def pmatR(xs: java.util.Vector[_]): String =
val scr = xs.get(0)
1.0 match
case `scr` => scr.toString() // for the reverse provablyDisjoint case
case _ => "shrug"

def test =
val x = new java.util.Vector[Double]()
x.add(1.0)
pmat(x)