@@ -4,6 +4,7 @@ package patmat
4
4
5
5
import core ._
6
6
import Types ._
7
+ import TypeUtils ._
7
8
import Contexts ._
8
9
import Flags ._
9
10
import ast ._
@@ -333,9 +334,11 @@ class SpaceEngine(using Context) extends SpaceLogic {
333
334
// Since projections of types don't include null, intersection with null is empty.
334
335
Empty
335
336
else
336
- val res = TypeComparer .provablyDisjoint(tp1, tp2)
337
- if res then Empty
338
- else Typ (AndType (tp1, tp2), decomposed = true )
337
+ val intersection = Typ (AndType (tp1, tp2), decomposed = true )
338
+ // unrelated numeric value classes can equal each other, so let's not consider type space interection empty
339
+ if tp1.classSymbol.isNumericValueClass && tp2.classSymbol.isNumericValueClass then intersection
340
+ else if TypeComparer .provablyDisjoint(tp1, tp2) then Empty
341
+ else intersection
339
342
}
340
343
341
344
/** Return the space that represents the pattern `pat` */
@@ -407,7 +410,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
407
410
case tp => Typ (tp, decomposed = true )
408
411
}
409
412
410
- private def unapplySeqInfo (resTp : Type , pos : SrcPos )( using Context ) : (Int , Type , Type ) = {
413
+ private def unapplySeqInfo (resTp : Type , pos : SrcPos ): (Int , Type , Type ) = {
411
414
var resultTp = resTp
412
415
var elemTp = unapplySeqTypeElemTp(resultTp)
413
416
var arity = productArity(resultTp, pos)
@@ -501,19 +504,20 @@ class SpaceEngine(using Context) extends SpaceLogic {
501
504
}
502
505
503
506
/** Numeric literals, while being constant values of unrelated types (e.g. Char and Int),
504
- * when used in a case may end up matching at runtime, because their equals may returns true.
505
- * Because these are universally available, general purpose types, it would be good to avoid
506
- * returning false positive warnings, such as in `(c: Char) match { case 67 => ... }` emitting a
507
+ * when used in a case may end up matching at runtime as their equals may returns true.
508
+ * Because these are universally available, general purpose types, it would be good to avoid,
509
+ * for example in `(c: Char) match { case 67 => ... }`, emitting a false positive
507
510
* reachability warning on the case. So the type `ConstantType(Constant(67, IntTag))` is
508
511
* converted to `ConstantType(Constant(67, CharTag))`. #12805 */
509
- def convertConstantType (tp : Type , pt : Type ): Type = tp match
512
+ def convertConstantType (tp : Type , pt : Type ): Type = trace( i " convertConstantType( $tp , $pt ) " , show = true )( tp match
510
513
case tp @ ConstantType (const) =>
511
514
val converted = const.convertTo(pt)
512
515
if converted == null then tp else ConstantType (converted)
513
516
case _ => tp
517
+ )
514
518
515
- def isPrimToBox (tp : Type , pt : Type ) =
516
- tp.classSymbol.isPrimitiveValueClass && (defn.boxedType(tp).classSymbol eq pt.classSymbol)
519
+ def isPrimToBox (tp : Type , pt : Type ): Boolean =
520
+ tp.isPrimitiveValueType && (defn.boxedType(tp).classSymbol eq pt.classSymbol)
517
521
518
522
/** Adapt types by performing primitive value unboxing or boxing, or numeric constant conversion. #12805
519
523
*
@@ -539,7 +543,10 @@ class SpaceEngine(using Context) extends SpaceLogic {
539
543
def isSubType (tp1 : Type , tp2 : Type ): Boolean = trace(i " $tp1 <:< $tp2" , debug, show = true ) {
540
544
if tp1 == constantNullType && ! ctx.mode.is(Mode .SafeNulls )
541
545
then tp2 == constantNullType
542
- else adaptType(tp1, tp2) <:< tp2
546
+ else
547
+ val tp1a = adaptType(tp1, tp2)
548
+ if tp1a eq tp1 then tp1 <:< tp2
549
+ else trace(i " $tp1a <:< $tp2 (adapted) " , debug, show = true )(tp1a <:< tp2)
543
550
}
544
551
545
552
def isSameUnapply (tp1 : TermRef , tp2 : TermRef ): Boolean =
@@ -872,7 +879,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
872
879
/** Return the underlying type of non-module, non-constant, non-enum case singleton types.
873
880
* Also widen ExprType to its result type, and rewrap any annotation wrappers.
874
881
* For example, with `val opt = None`, widen `opt.type` to `None.type`. */
875
- def toUnderlying (tp : Type )( using Context ) : Type = trace(i " toUnderlying( $tp) " , show = true )(tp match {
882
+ def toUnderlying (tp : Type ): Type = trace(i " toUnderlying( $tp) " , show = true )(tp match {
876
883
case _ : ConstantType => tp
877
884
case tp : TermRef if tp.symbol.is(Module ) => tp
878
885
case tp : TermRef if tp.symbol.isAllOf(EnumCase ) => tp
0 commit comments