@@ -502,12 +502,13 @@ class SpaceEngine(using Context) extends SpaceLogic {
502
502
503
503
/** Is `tp1` a subtype of `tp2`? */
504
504
def isSubType (tp1 : Type , tp2 : Type ): Boolean = {
505
- debug.println(TypeComparer .explained(_.isSubType(tp1, tp2)))
505
+ // debug.println(TypeComparer.explained(_.isSubType(tp1, tp2)))
506
506
val res = if (ctx.explicitNulls) {
507
507
tp1 <:< tp2
508
508
} else {
509
509
(tp1 != constantNullType || tp2 == constantNullType) && tp1 <:< tp2
510
510
}
511
+ debug.println(i " $tp1 <:< $tp2 = $res" )
511
512
res
512
513
}
513
514
@@ -663,7 +664,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
663
664
|| cls.isAllOf(JavaEnumTrait )
664
665
|| tp.isRef(defn.BooleanClass )
665
666
|| tp.isRef(defn.UnitClass )
666
- debug.println(s " decomposable: ${tp.show} = $res" )
667
+ // debug.println(s"decomposable: ${tp.show} = $res")
667
668
res
668
669
669
670
/** Show friendly type name with current scope in mind
@@ -838,14 +839,26 @@ class SpaceEngine(using Context) extends SpaceLogic {
838
839
}
839
840
}.apply(false , tp)
840
841
842
+ /** Return the underlying type of non-module, non-constant, non-enum case singleton types.
843
+ * Also widen ExprType to its result type.
844
+ * For example, with `val opt = None`, widen `opt.type` to `None.type`. */
845
+ def toUnderlying (tp : Type )(using Context ): Type = trace(i " toUnderlying( $tp) " , show = true )(tp match {
846
+ case _ : ConstantType => tp
847
+ case tp : TermRef if tp.symbol.is(Module ) => tp
848
+ case tp : TermRef if tp.symbol.isAllOf(EnumCase ) => tp
849
+ case tp : SingletonType => toUnderlying(tp.underlying)
850
+ case tp : ExprType => toUnderlying(tp.resultType)
851
+ case _ => tp
852
+ })
853
+
841
854
def checkExhaustivity (_match : Match ): Unit = {
842
855
val Match (sel, cases) = _match
843
- val selTyp = sel.tpe.widen.dealias
856
+ debug.println( i " checking exhaustivity of ${_match} " )
844
857
845
858
if (! exhaustivityCheckable(sel)) return
846
859
847
- debug.println( " checking " + _match.show)
848
- debug.println(" selTyp = " + selTyp.show )
860
+ val selTyp = toUnderlying(sel.tpe).dealias
861
+ debug.println(i " selTyp = $ selTyp" )
849
862
850
863
val patternSpace = Or (cases.foldLeft(List .empty[Space ]) { (acc, x) =>
851
864
val space = if (x.guard.isEmpty) project(x.pat) else Empty
@@ -878,13 +891,14 @@ class SpaceEngine(using Context) extends SpaceLogic {
878
891
&& ! sel.tpe.widen.isRef(defn.QuotedTypeClass )
879
892
880
893
def checkRedundancy (_match : Match ): Unit = {
881
- debug.println(s " ---------------checking redundant patterns ${_match.show}" )
882
-
883
894
val Match (sel, cases) = _match
884
- val selTyp = sel.tpe.widen.dealias
895
+ debug.println( i " checking redundancy in $_match " )
885
896
886
897
if (! redundancyCheckable(sel)) return
887
898
899
+ val selTyp = toUnderlying(sel.tpe).dealias
900
+ debug.println(i " selTyp = $selTyp" )
901
+
888
902
val targetSpace =
889
903
if ! selTyp.classSymbol.isNullableClass then
890
904
project(selTyp)
@@ -897,7 +911,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
897
911
if (x.guard.isEmpty) project(x.pat)
898
912
else Empty
899
913
900
- debug.println(s " ${x.pat.show} ====> ${res}" )
914
+ debug.println(s " ${x.pat.show} ====> ${show( res) }" )
901
915
res
902
916
}
903
917
@@ -912,7 +926,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
912
926
debug.println(s " prev: ${show(prevs)}" )
913
927
914
928
var covered = simplify(intersect(curr, targetSpace))
915
- debug.println(s " covered: $covered" )
929
+ debug.println(s " covered: ${show( covered)} " )
916
930
917
931
// `covered == Empty` may happen for primitive types with auto-conversion
918
932
// see tests/patmat/reader.scala tests/patmat/byte.scala
0 commit comments