Skip to content

Allow infallible boolean extractors to return true type #4226

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
LPTK opened this issue Apr 2, 2018 · 0 comments
Closed

Allow infallible boolean extractors to return true type #4226

LPTK opened this issue Apr 2, 2018 · 0 comments

Comments

@LPTK
Copy link
Contributor

LPTK commented Apr 2, 2018

The following code (here in Scastie) does not currently work:

sealed abstract class Maybe[A]
final case class Just[A](a: A) extends Maybe[A]
class Empty[A] extends Maybe[A]
object Empty {
  def apply[A](): Maybe[A] = new Empty[A]
  // def unapply[A](e: Empty[A]): Boolean = true  // ok
  def unapply[A](e: Empty[A]): true = true
}

object Test {
  val a: Maybe[Int] = Just(2)
  def main(args: Array[String]): Unit = a match {
    case Just(2) => true
    case Empty() =>
    // ^ Boolean(true) is not a valid result type of an unapply method of an extractor()
  }
}

Though it should arguably compile and raise an exhaustivity warning (because it does not match Just(n) for n != 2).

@liufengyun liufengyun self-assigned this Apr 2, 2018
liufengyun added a commit to dotty-staging/dotty that referenced this issue Apr 3, 2018
liufengyun added a commit to dotty-staging/dotty that referenced this issue Apr 6, 2018
liufengyun added a commit that referenced this issue Apr 11, 2018
Fix #4226: allow infallible boolean extractors to return `true`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants