Skip to content

Fix #8690: the signature for product should come from expected type #8698

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

Merged
merged 13 commits into from
Apr 14, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ object PickledQuotes {
case tp: TypeRef =>
typeSpliceMap.get(tp.symbol) match
case Some(t) if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => t
case None => tp
case _ => tp
case _ => tp
}
mapOver(tp1)
Expand Down
165 changes: 102 additions & 63 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/neg-custom-args/isInstanceOf/enum-approx2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sealed trait Exp[T]
case class Fun[A, B](f: Exp[A => B]) extends Exp[A => B]

class Test {
def eval[T](e: Exp[T]) = e match {
def eval(e: Fun[Int, Int]) = e match {
case Fun(x: Fun[Int, Double]) => ??? // error
case Fun(x: Exp[Int => String]) => ??? // error
}
Expand Down
1 change: 1 addition & 0 deletions tests/patmat/exhaustive_heuristics.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11: Pattern Match Exhaustivity: _: List
7 changes: 7 additions & 0 deletions tests/patmat/i8690.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class A
class B

def test(x: (A, B) | (B, A)) = x match {
case (u: A, v) => (u, v)
case (u: B, v) => (v, u)
}
7 changes: 7 additions & 0 deletions tests/patmat/i8690b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class A
class B

def test(x: (A, B) | (B, A)) = x match {
case (u: A, v: B) => (u, v)
case (u: B, v: A) => (v, u)
}
1 change: 1 addition & 0 deletions tests/patmat/i8708.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2: Pattern Match Exhaustivity: Some(_)
8 changes: 8 additions & 0 deletions tests/patmat/i8708.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Main {
def foo(x: Option[Int]): Int = x match {
case Some(n) if n % 2 == 0 => n
case None => 0
}

def main(args: Array[String]): Unit = println(foo(Some(1)))
}
1 change: 1 addition & 0 deletions tests/patmat/patmatexhaust.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
11: Pattern Match Exhaustivity: Bar(_)
23: Pattern Match Exhaustivity: (Qult(), Qult()), (Kult(_), Kult(_))
49: Pattern Match Exhaustivity: _: Gp
53: Pattern Match Exhaustivity: _: Gp
59: Pattern Match Exhaustivity: Nil
75: Pattern Match Exhaustivity: _: B
87: Pattern Match Exhaustivity: _: C1
Expand Down
24 changes: 24 additions & 0 deletions tests/patmat/t11457b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sealed trait Command {
type Reply
}

final case class Create() extends Command {
type Reply = CreateReply
val reply: Reply = CreateReply()
}

final case class Set() extends Command {
type Reply = SetReply
val reply: Reply = SetReply()
}

case class CreateReply()
case class SetReply()

def process[R](command: Command { type Reply = R }): R =
command match {
case create: Create => create.reply
case set: Set => set.reply
// ^
// Warning: unreachable code
}
16 changes: 16 additions & 0 deletions tests/patmat/t11620b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sealed abstract class Length

object Length {
case class Num(n: Int) extends Length
case object StateColumn extends Length
}

import Length._

case class Indent[T <: Length](length: T)

def withIndent[T <: Length](indent: => Indent[_]): Unit =
indent match {
case Indent(Num(0)) => println("this")
case x => println(x) // "unreachable"
}
2 changes: 1 addition & 1 deletion tests/patmat/t7631.check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8: Pattern Match Exhaustivity: TestB()
8: Pattern Match Exhaustivity: _: Test
2 changes: 1 addition & 1 deletion tests/patmat/virtpatmat_apply.check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2: Pattern Match Exhaustivity: List(_)
2: Pattern Match Exhaustivity: List(_, _: _*)