torture.scala 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package com.example.torture
  2. import com.example.other.OtherClass
  3. import com.example.multi.{Alpha, Beta}
  4. import com.example.wild._
  5. import com.example.star.*
  6. import com.example.alias.{LongName => Short}
  7. /** Scaladoc for topLevel — kept? */
  8. def topLevel(a: Int): WidgetS = new WidgetS(a)
  9. // line one
  10. // line two
  11. def lineDoc(): Int = 1
  12. def curried(a: Int)(b: String)(implicit ord: Ordering[Int]): Int = a
  13. def genericDef[A: Numeric, B <: BoundT](x: A): B = ???
  14. def inferredRet(a: Int) = a + 1
  15. def unitRet(): Unit = ()
  16. def genericLeak[T](t: T): T = t
  17. def qualRet(w: WidgetS): com.example.other.Remote = ???
  18. private def privTop(): Int = 1
  19. @main def entry(): Unit = topLevel(1)
  20. @deprecated("gone", "1.0") def old(): Int = 0
  21. val topVal: Int = 3
  22. var topVar = 4
  23. lazy val topLazy = compute()
  24. val (tupA, tupB) = (1, 2)
  25. val Some(extracted) = Option(9)
  26. val SHARED_TABLE: Map[String, Int] = Map.empty
  27. val topInit = WidgetS.create()
  28. class WidgetS(val size: Int, label: String = defaultLabel()) extends BaseW(size) with Drawable with Ordered[WidgetS] {
  29. val cachedName: String = "w"
  30. var mutable = 0
  31. private val secret = 3
  32. @volatile var annotatedField: Int = 0
  33. def this() = this(0, "d")
  34. def render(): RenderResult = {
  35. val local = helperR(size)
  36. Registry.register(this)
  37. new RenderResult(local)
  38. }
  39. def +(other: WidgetS): WidgetS = new WidgetS(size + other.size)
  40. def compare(that: WidgetS): Int = size - that.size
  41. @inline def fast(): Int = 1
  42. protected def hook(): Unit = ()
  43. }
  44. object WidgetS {
  45. val DEFAULT_SIZE = 10
  46. def create(): WidgetS = new WidgetS(DEFAULT_SIZE, "c")
  47. def readDefault(): Int = DEFAULT_SIZE + 1
  48. }
  49. case class DataS(x: Int, y: String = mkY())
  50. case object SingletonS extends MarkerT
  51. abstract class AbsS {
  52. def abstractM(): Int
  53. def concrete(): Int = abstractM() + 1
  54. }
  55. trait Drawable {
  56. def draw(): Unit
  57. def area(): Double = 0.0
  58. val traitVal: Int = 7
  59. }
  60. sealed trait Shape
  61. object Circle extends Shape
  62. class Square extends Shape
  63. trait MarkerT
  64. class DelegatedImpl(d: Drawable) extends Drawable {
  65. def draw(): Unit = d.draw()
  66. }
  67. enum Http {
  68. case Ok, NotFound
  69. case Custom(code: Int)
  70. def describe(): String = s"code"
  71. }
  72. enum Planet(mass: Double) {
  73. case Earth extends Planet(5.9)
  74. case Mars extends Planet(0.6)
  75. }
  76. given intOrd: Ordering[WidgetS] = new Ordering[WidgetS] {
  77. def compare(a: WidgetS, b: WidgetS): Int = a.size - b.size
  78. }
  79. given String = "anon"
  80. extension (s: String)
  81. def doubleUp: String = concat(s, s)
  82. def tripleUp: String = concat(s, concat(s, s))
  83. extension [A](xs: List[A]) def secondOpt: Option[A] = xs.drop(1).headOption
  84. implicit class RichIntS(val i: Int) {
  85. def twice: Int = i * 2
  86. }
  87. type WidgetList = List[WidgetS]
  88. opaque type Meters = Double
  89. object CallSites {
  90. def run(w: WidgetS): Unit = {
  91. helper(1)
  92. w.render()
  93. WidgetS(1)
  94. WidgetS.create().render()
  95. lowerFactory().chain()
  96. a.b.method3()
  97. this.mine()
  98. super.hashCode()
  99. "lit".toUpperCase()
  100. 5.toString()
  101. genericCall[Int](1)
  102. val n2 = new Ordering[Int] { def compare(p: Int, q: Int): Int = p - q }
  103. val s1 = s"plain $topVal and ${w.render()} end"
  104. val e1 = registerCb(handler _)
  105. val e2 = handler _
  106. registerCb(handler)
  107. val r1 = list map transform
  108. val r2 = 1 :: rest
  109. w match {
  110. case ws: WidgetS => use(ws)
  111. case _ => ()
  112. }
  113. for { x <- xs; y <- ys if y > 0 } yield combineXY(x, y)
  114. }
  115. def mine(): Int = 1
  116. def handler(): Unit = ()
  117. def localHost(): Int = {
  118. def innerFn(k: Int): Int = k * 2
  119. val lam = (q: Int) => q + 1
  120. class LocalClass { def lm(): Int = 3 }
  121. object LocalObj { def om(): Int = 4 }
  122. innerFn(lam(1)) + helperCall()
  123. }
  124. }
  125. object StaticReads {
  126. def reads(): Unit = {
  127. val c1 = Registry.count
  128. val c2 = Http.Ok
  129. val c3 = com.example.Fq.CONST_READ
  130. Registry.count = 5
  131. process(Registry.count)
  132. Registry.register(null)
  133. }
  134. }
  135. package object utilpkg {
  136. def pkgHelper(): Int = 1
  137. val pkgShared = 2
  138. }