summaryrefslogtreecommitdiff
path: root/test/files/presentation/parse-invariants/src/a/A.scala
blob: 1ae78cad050f55fc461ed8d02dcbbd51ae6b7ce1 (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
package syntax

object Terms {
  object Literals {
    0
    0l
    0f
    0d
    0xb33f
    'c'
    "string"
    """
      multi-line
      string
    """
    'symbol
    true
    false
    null
    ()
  }

  object Patterns {
    0             match { case 0                               =>               }
    1             match { case (0 | 1)                         =>               }
    2             match { case _: Int                          =>               }
    3             match { case _                               =>               }
    Some(0)       match { case Some(0)                         =>               }
    Some(0)       match { case name @ Some(_)                  =>               }
    Some(Some(0)) match { case nested @ Some(deeper @ Some(_)) =>               }
    List(1, 2, 3) match { case unapplySeq @ List(1, 2, _*)     =>               }
    0             match { case i if i > 0                      =>               }
    List(1)       match { case _: List[t]                      => List.empty[t] }
  }

  object New {
    class Foo
    trait Bar
    new Foo
    new Foo { selfie => }
    new Foo with Bar
    new { val early = 1 } with Bar
    new { val name = "anon "}
  }

  def tuple         = (1, 'two, "three")
  def lambda        = (x: Int, y: Int) => x + y
  def lambda2       = (_: Int) + (_: Int)
  def blocks        = { { {}; {} }; {} }
  def ascription    = (1: Int)
  def select        = Nil.size
  def method1       = "s".replace("foo", "bar")
  def method2       = "s" + "s"
  def method3       = Nil.foreach { e => }
  def method4       = 1 :: 2 :: 3 :: Nil
  def if1           = if (true) true else false
  def if2           = if (true) true
  def `return`: Int = { return 0 }
  def `throw`       = throw new Exception
  def `match`       = 0 match { case 0 => case _ => }
  def `try`         = try 0 catch { case _ => } finally 0
  def `while`       = while(true) 0
  def `do while`    = do 0 while(true)
  def `for`         = for (i <- 1 to 10; if i % 2 == 0; j = i + 1) j
  def `for yield`   = for (a <- List(List(1)); b <- a; c = b * 2) yield b
  def interpolation = s"$tuple and maybe also $blocks"
  def assign        = { var x = 1; x = 2 }
  def assign2       = { object o { var x = 1 }; o.x = 2 }
  def update        = { val v = collection.mutable.Seq(1); v(0) = 2 }
  def `this`        = this
}

object Types {
  type Reference    = scala.App
  type Tuple        = (Int, String, Double)
  type Function     = (Int, String) => Double
  type Refined      = Int { val meta: Any }
  type Lambda       = ({ type F[T] = List[T] })#F[_]
  type Infix        = Int Either String
  type Application  = List[Int]
  type Existential  = List[T] forSome { type T }
  object O { type T = Int }
  type Dependent    = O.T
  class O { type T  = Int }
  type Selection    = O#T
}

object Definitions {
  private val x1 = 0
  private[this] val x2 = 0
  private[Definitions] val x3 = 0
  protected val x4 = 0
  protected[AcessManagement] val x5 = 0
  val x1 = 1
  val x2: Int = 1
  val x3, y3 = 1
  lazy val x4 = 1
  implicit val x5 = 1
  final val x6 = 1
  lazy final val x7 = 1
  val Some(x8) = Some(0)
  var x9 = 1
  var x10, y10 = 1
  var x11: Int = 1

  implicit def implicitView: Option[Int] = None
  def implicitArg1(implicit i: Int) = i + 2
  def implicitArg2[T: Fooable] = implicitly[Fooable[T]]
  def bound1[T <: Int](x: T): T = x
  def bound2[T >: Any](x: T): T = x
  def bound3[T <% Int](x: T): Int = x
  def vararg(args: Int*) = args.toList
  def sum(x: Int, y: Int) = x + y
  def multipleArgLists(x: Int)(y: Int) = x + y

  type _0 = Int
  type _1[T] = List[T]
  type _2[A, B] = Either[A, B]

  class Val(value: Int) extends AnyVal
  implicit class Impl(value: Int) { def foo = "foo" }
  abstract class Abs
  sealed class Sealed
  class Child extends Sealed
  case class Point(x: Int, y: Int)

  trait Fooable[T]
  trait Barable with Fooable[Barable]

  object Foo
  object Foo with Fooable[Foo]
  case object Zero
}

package Packages {
  package object PackageObject
  package Nested { package Deeper { } }
}