Skip to content

WIP: resolves lampepfl#13737 #13961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,12 @@ class SpaceEngine(using Context) extends SpaceLogic {
Prod(erase(pat.tpe.stripAnnots, isValue = false), funRef, pats.take(arity - 1).map(project) :+ projectSeq(pats.drop(arity - 1)))
}
else
Prod(erase(pat.tpe.stripAnnots, isValue = false), funRef, pats.map(project))
val tp = fun.tpe.widen.finalResultType
val isProdMatch = isProductMatch(tp, pats.length) || defn.isProductSubType(tp) && tp.classSymbol.is(Scala2x)
if isProdMatch then
Prod(erase(pat.tpe.stripAnnots, isValue = false), funRef, pats.map(project))
else
Typ(erase(pat.tpe.stripAnnots, isValue = false), decomposed = false)

case Typed(pat @ UnApply(_, _, _), _) =>
project(pat)
Expand Down
1 change: 1 addition & 0 deletions tests/patmat/irrefutable.mini.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15: Pattern Match Exhaustivity: ExM(_, _)
18 changes: 18 additions & 0 deletions tests/patmat/irrefutable.mini.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sealed class M(n: Int, s: String) extends Product {
def _1: Int = n
def _2: String = s
def isEmpty: Boolean = s.size > n
def get: M = this

def canEqual(that: Any): Boolean = true
def productArity: Int = 2
def productElement(n: Int): Any = ???
}

object ExM {
def unapply(m: M): M = m

def test(m: M) = m match { // warning
case ExM(s) =>
}
}
18 changes: 18 additions & 0 deletions tests/pos/i13737.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sealed trait Result

case class Success(result: String, next: Int) extends Result {
def isEmpty: Boolean = 10 % 2 == 1
def get: String = result
}

object Success {
def unapply(x: Success): Success = x
}

def main =
val res: Result = ???
res match
case Success(v) => v


// todo: check why only sealed trait interference