aboutsummaryrefslogtreecommitdiff
path: root/tests/invalid/pos/patmat.scala
blob: 53e1c5f1fc9d5db644f054057d3e774787365444 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// these used to be in test/files/run/patmatnew.scala
// the ticket numbers are from the old tracker, not Trac

object ZipFun {
  //just compilation
  def zipFun[a, b](xs: List[a], ys: List[b]): List[Tuple2[a, b]] = ((xs, ys): @unchecked) match {
    // !!! case (List(), _), (_, List()) => List()
    case (x :: xs1, y :: ys1) => (x, y) :: zipFun(xs1, ys1)
  }
}

object Test1253 { // compile-only
  def foo(t: (Int, String)) = t match {
    case (1, "") => throw new Exception
    case (r, _) => throw new Exception(r.toString)
  }
}

object Foo1258 {
  case object baz
  def foo(bar: AnyRef) = {
    val Baz = baz
    bar match {
      case Baz => ()
    }
  }
}

object t1261 {
  sealed trait Elem
  case class Foo() extends Elem
  case class Bar() extends Elem
  trait Row extends Elem
  object Row {
    def unapply(r: Row) = true

    def f(elem: Elem): Unit = {
      elem match {
        case Bar() => ;
        case Row() => ;
        case Foo() => ; // used to give ERROR (unreachable code)
      }
    }
  }
}

sealed abstract class Tree
case class Node(l: Tree, v: Int, r: Tree) extends Tree
case object EmptyTree extends Tree

object Ticket335 { // compile-only
  def runTest(): Unit = {
    (EmptyTree: Tree @unchecked) match {
      case Node(_, v, _) if (v == 0) => 0
      case EmptyTree => 2
    }
  }
}

object TestIfOpt { //compile-only "test EqualsPatternClass in combination with MixTypes opt, bug #1278"
  trait Token {
    val offset: Int
    def matching: Option[Token]
  }
  def go(tok: Token) = (tok.matching: @unchecked) match {
    case Some(other) if true => Some(other)
    case _ if true => tok.matching match {
      case Some(other) => Some(other)
      case _ => None
    }
  }
}

object Go { // bug #1277 compile-only
  trait Core { def next: Position = null }
  trait Dir
  val NEXT = new Dir {}

  trait Position extends Core

  (null: Core, null: Dir) match {
    case (_, NEXT) if true => false // no matter whether NEXT test succeed, cannot throw column because of guard
    case (at2: Position, dir) => true
  }
}

trait Outer { // bug #1282 compile-only
  object No
  trait File {
    (null: AnyRef) match {
      case No => false
    }
  }
}

class Test806_818 { // #806, #811 compile only -- type of bind
  // t811
  trait Core {
    trait NodeImpl
    trait OtherImpl extends NodeImpl
    trait DoubleQuoteImpl extends NodeImpl
    def asDQ(node: OtherImpl) = node match {
      case dq: DoubleQuoteImpl => dq
    }
  }

  trait IfElseMatcher {
    type Node <: NodeImpl
    trait NodeImpl
    trait IfImpl
    private def coerceIf(node: Node) = node match {
      case node: IfImpl => node // var node is of type Node with IfImpl!
      case _ => null
    }
  }
}

object Ticket495bis {
  def signum(x: Int): Int =
    x match {
      case 0 => 0
      case _ if x < 0 => -1
      case _ if x > 0 => 1
    }
  def pair_m(x: Int, y: Int) =
    (x, y) match {
      case (_, 0) => 0
      case (-1, _) => -1
      case (_, _) => 1
    }
}

object Ticket522 {
  class Term[X]
  object App {
    // i'm hidden
    case class InternalApply[Y, Z](fun: Y => Z, arg: Y) extends Term[Z]

    def apply[Y, Z](fun: Y => Z, arg: Y): Term[Z] =
      new InternalApply[Y, Z](fun, arg)

    def unapply[X](arg: Term[X]): Option[(Y => Z, Y)] forSome { type Y; type Z } =
      arg match {
        case i: InternalApply[y, z] => Some(i.fun, i.arg)
        case _ => None
      }
  }

  App({ x: Int => x }, 5) match {
    case App(arg, a) =>
  }
}

object Ticket710 {
  def method: Unit = {
    sealed class Parent()
    case object Child extends Parent()
    val x: Parent = Child
    x match {
      case Child => ()
    }
  }
}