Skip to content

Commit 0f5b996

Browse files
authored
Merge pull request #15769 from dwijnand/unreachable-doubles
Teach provablyDisjoint to handle FromJavaObject
2 parents 34f56c2 + 7365595 commit 0f5b996

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,6 +2600,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
26002600
}.apply(true, tp)
26012601

26022602
(tp1.dealias, tp2.dealias) match {
2603+
case _ if !ctx.erasedTypes && tp2.isFromJavaObject =>
2604+
provablyDisjoint(tp1, defn.AnyType)
2605+
case _ if !ctx.erasedTypes && tp1.isFromJavaObject =>
2606+
provablyDisjoint(defn.AnyType, tp2)
26032607
case (tp1: TypeRef, _) if tp1.symbol == defn.SingletonClass =>
26042608
false
26052609
case (_, tp2: TypeRef) if tp2.symbol == defn.SingletonClass =>

tests/pos/i15717.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// scalac: -Werror
2+
class Test:
3+
def pmat(xs: java.util.Vector[_]): String = xs.get(0) match
4+
case d: Double => d.toString() // was: error: unreachable case, which is spurious
5+
case _ => "shrug"
6+
7+
def pmatR(xs: java.util.Vector[_]): String =
8+
val scr = xs.get(0)
9+
1.0 match
10+
case `scr` => scr.toString() // for the reverse provablyDisjoint case
11+
case _ => "shrug"
12+
13+
def test =
14+
val x = new java.util.Vector[Double]()
15+
x.add(1.0)
16+
pmat(x)

0 commit comments

Comments
 (0)