@@ -903,24 +903,25 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
903903 def checkRedundancy (_match : Match ): Unit = {
904904 val Match (sel, cases) = _match
905905 // ignore selector type for now
906- // val selTyp = sel.tpe.widen.dealias
907-
908- if (cases.length == 1 ) return
906+ val selTyp = sel.tpe.widen.dealias
909907
910- // starts from the second, the first can't be redundant
911- (1 until cases.length).foreach { i =>
908+ (0 until cases.length).foreach { i =>
912909 // in redundancy check, take guard as false in order to soundly approximate
913- val prevs = cases.take(i).map { x =>
914- if (x.guard.isEmpty) project(x.pat)
915- else Empty
916- }.reduce((a, b) => Or (List (a, b)))
910+ val prevs =
911+ if (i == 0 )
912+ Empty
913+ else
914+ cases.take(i).map { x =>
915+ if (x.guard.isEmpty) project(x.pat)
916+ else Empty
917+ }.reduce((a, b) => Or (List (a, b)))
917918
918919 val curr = project(cases(i).pat)
919920
920921 debug.println(s " ---------------reachable? ${show(curr)}" )
921922 debug.println(s " prev: ${show(prevs)}" )
922923
923- if (isSubspace(curr, prevs)) {
924+ if (isSubspace(intersect( curr, Typ (selTyp, false )) , prevs)) {
924925 ctx.warning(MatchCaseUnreachable (), cases(i).body.pos)
925926 }
926927 }
0 commit comments