forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSynthetic.scala
70 lines (57 loc) · 1.6 KB
/
Synthetic.scala
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
package example
import scala.language.implicitConversions
class Synthetic {
List(1).map(_ + 2)
Array.empty[Int].headOption
"fooo".stripPrefix("o")
// See https://github.com/scalameta/scalameta/issues/977
val Name = "name:(.*)".r
val x #:: xs = LazyList(1, 2): @unchecked
val Name(name) = "name:foo": @unchecked
1 #:: 2 #:: LazyList.empty
val a1 #:: a2 #:: as = LazyList(1, 2): @unchecked
val lst = 1 #:: 2 #:: LazyList.empty
for (x <- 1 to 10; y <- 0 until 10) println(x -> x)
for (i <- 1 to 10; j <- 0 until 10) yield (i, j)
for (i <- 1 to 10; j <- 0 until 10 if i % 2 == 0) yield (i, j)
object s {
def apply() = 2
s()
s.apply()
case class Bar()
Bar()
null.asInstanceOf[Int => Int](2)
}
class J[T: Manifest] { val arr = Array.empty[T] }
class F
implicit val ordering: Ordering[F] = ???
val f: Ordered[F] = new F
import scala.concurrent.ExecutionContext.Implicits.global
for {
a <- scala.concurrent.Future.successful(1)
b <- scala.concurrent.Future.successful(2)
} println(a)
for {
a <- scala.concurrent.Future.successful(1)
b <- scala.concurrent.Future.successful(2)
if a < b
} yield a
object Contexts {
def foo(x: Int)(using Int) = ???
def m1(using Int) = foo(0)
def m2(using x: Int) = foo(0)
def m3 =
given x: Int = 1
foo(x)
def m4 =
given Int = 1
foo(0)
}
// Argument lifting
val _ =
def f(s: String)(i: Int = s.length()) = i + 1
def g(s: String, t: String) = s + t
def impure(s: String) = { ???; s }
val _ = f(impure(""))()
val _ = g(t = impure(""), s = "a")
}