aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
authorDmitry Petrashko <dark@d-d.me>2015-05-04 22:03:22 +0200
committerDmitry Petrashko <dark@d-d.me>2015-05-04 22:03:22 +0200
commitc4dba2420be56e628e37732a3369533951cc7ef1 (patch)
tree531b4f22bc8be035a765c51d9b0cd1417dfd5aef /tests/pos
parent7c8693b62bfa73a47eb781bf0e372f68acc0db52 (diff)
parent349c436348407b0e862e3feb65c959275549d86b (diff)
downloaddotty-c4dba2420be56e628e37732a3369533951cc7ef1.tar.gz
dotty-c4dba2420be56e628e37732a3369533951cc7ef1.tar.bz2
dotty-c4dba2420be56e628e37732a3369533951cc7ef1.zip
Merge pull request #509 from dotty-staging/add/expandSAMs
Expand SAM closures to anonymous classes if needed
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/Patterns.scala5
-rw-r--r--tests/pos/sams.scala75
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/pos/Patterns.scala b/tests/pos/Patterns.scala
index e443c2ab5..e9bce87a9 100644
--- a/tests/pos/Patterns.scala
+++ b/tests/pos/Patterns.scala
@@ -94,3 +94,8 @@ object Patterns {
t
}
}
+
+object NestedPattern {
+ val xss: List[List[String]] = ???
+ val List(List(x)) = xss
+}
diff --git a/tests/pos/sams.scala b/tests/pos/sams.scala
new file mode 100644
index 000000000..b7ef7dd2d
--- /dev/null
+++ b/tests/pos/sams.scala
@@ -0,0 +1,75 @@
+object test {
+
+ trait X { def foo(x: Int): Int; def bar = foo(2) }
+
+ val x: X = (x: Int) => 2 // should be a closure
+
+ trait T {
+ var f = 2
+ def foo(x: Int): Int
+ }
+
+ val t: T = (x: Int) => 2 // needs to be an anonymous class because of defined field
+
+ trait U extends T
+
+ val u: U = (x: Int) => 2 // needs to be an anonymous class because of inherited field
+
+ trait V extends Exception { def foo(x: Int): Int }
+
+ val v: V = (x: Int) => 2 // needs to be an anonymous class because the trait extends a non-object class
+
+ trait Y extends X {
+ def baz = super.bar
+ }
+
+ val y: Y = (x: Int) => 2 // needs to be an anonymous class because of super accessor
+
+ trait Z {
+ def foo(x: Int): Int; println("hi there!")
+ }
+ trait ZZ extends Z
+
+ val z: Z = (x: Int) => 2 // needs to be an anonymous class because trait has initialization code
+ val zz: ZZ = (x: Int) => 2 // needs to be an anonymous class becaiuse trait has initialization code
+
+ abstract class C {
+ def foo(x: Int): Int
+
+ trait I { def foo(x: Int): Int }
+
+ }
+
+ val c: C = (x: Int) => 2 // needs to be an anonymous class because C is not a trait
+
+ val ci: c.I = (x: Int) => 2 // needs to be an anonymous class because it needs an outer pointer
+
+
+ val pf: PartialFunction[Int, Int] = {
+ case 1 => 1
+ case 2 => 2
+ }
+
+ val qf: PartialFunction[(Int, String), Int] = {
+ case (1, "abc") => 1
+ case _ => 2
+ }
+
+ val rf: PartialFunction[(Int, AnyRef), Int] = {
+ case (_: Int, _: String) => 1
+ case _ => 2
+ }
+
+ val sf: PartialFunction[Any, Int] = {
+ case x: String if x == "abc" => 1
+ }
+}
+
+// From: neg/sammy_poly
+// synthesizeSAMFunction where the sam type is not fully defined
+class T {
+ trait F[T, U] { def apply(x: T): U }
+ // this is an inner trait, that will recieve an abstract $outer pointer. Not a SAM.
+ def app[T, U](x: T)(f: F[T, U]): U = f(x)
+ app(1)(x => List(x))
+}