diff options
author | Martin Odersky <odersky@gmail.com> | 2016-12-15 15:21:26 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-12-15 15:21:26 +0100 |
commit | b1553cb9c5894e2e91925a67afd2c986675e5c46 (patch) | |
tree | f9def6ae664f0df939a51b55c5283790b93a7c4d /tests/pos/Patterns.scala | |
parent | 9bf58090c704a59d8735874c565200758bcea666 (diff) | |
download | dotty-b1553cb9c5894e2e91925a67afd2c986675e5c46.tar.gz dotty-b1553cb9c5894e2e91925a67afd2c986675e5c46.tar.bz2 dotty-b1553cb9c5894e2e91925a67afd2c986675e5c46.zip |
Implement new rules for name-based pattern matching
This implements the rules laid down in #1805.
Diffstat (limited to 'tests/pos/Patterns.scala')
-rw-r--r-- | tests/pos/Patterns.scala | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/pos/Patterns.scala b/tests/pos/Patterns.scala index aa369a77b..fd0d7e97a 100644 --- a/tests/pos/Patterns.scala +++ b/tests/pos/Patterns.scala @@ -108,3 +108,31 @@ object NestedPattern { val xss: List[List[String]] = ??? val List(List(x)) = xss } + +// Tricky case (exercised by Scala parser combinators) where we use +// both get/isEmpty and product-based pattern matching in different +// matches on the same types. +object ProductAndGet { + + trait Result[+T] + case class Success[+T](in: String, x: T) extends Result[T] { + def isEmpty = false + def get: T = x + } + case class Failure[+T](in: String, msg: String) extends Result[T] { + def isEmpty = false + def get: String = msg + } + + val r: Result[Int] = ??? + + r match { + case Success(in, x) => x + case Failure(in, msg) => -1 + } + + r match { + case Success(x) => x + case Failure(msg) => -1 + } +} |