From 7365595b4fdd0a12fe9983371422f0b3583ffbdb Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 27 Jul 2022 17:45:05 +0100 Subject: [PATCH] Teach provablyDisjoint to handle FromJavaObject SpaceEngine makes use of provablyDisjoint, using its Empty space as a result. In the test case the scrutinee is of type xs.E, which has info `>: Nothing <: `, which isn't a subtype of Double and Double isn't a subtype of it either. But their intersection does exist, in boxed Double. The code here is exactly like FromJavaObject is handled in isSubType's "firstTry". --- .../src/dotty/tools/dotc/core/TypeComparer.scala | 4 ++++ tests/pos/i15717.scala | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/pos/i15717.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 8c41390a38d2..831b292fba21 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -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 => diff --git a/tests/pos/i15717.scala b/tests/pos/i15717.scala new file mode 100644 index 000000000000..d625d9ccb039 --- /dev/null +++ b/tests/pos/i15717.scala @@ -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)