diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-10-03 23:02:27 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-10-04 10:55:17 -0700 |
commit | 67062db57c1abef88e0049dac5d82d4f13375a48 (patch) | |
tree | 69cebe4522d71b8c9241ab887a486382106a6c3e /test/files/pos | |
parent | 657e85fe2412cdadc5ee9dc348159b32dcdfcba7 (diff) | |
download | scala-67062db57c1abef88e0049dac5d82d4f13375a48.tar.gz scala-67062db57c1abef88e0049dac5d82d4f13375a48.tar.bz2 scala-67062db57c1abef88e0049dac5d82d4f13375a48.zip |
Single Abstract Method support: synthesize SAMs
Under `-Xexperimental`, `typedFunction` invokes `synthesizeSAMFunction`
when the expected type for the function literal (`pt`) is not the built-in
`FunctionN` type of the expected arity, but `pt` does have a SAM
with the expected number of arguments.
PS: We'll require `import language.sam` instead of `-Xexperimental`,
as soon as the SIP is ready and there are more tests.
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/sammy_poly.flags | 1 | ||||
-rw-r--r-- | test/files/pos/sammy_poly.scala | 6 | ||||
-rw-r--r-- | test/files/pos/sammy_scope.flags | 1 | ||||
-rw-r--r-- | test/files/pos/sammy_scope.scala | 8 | ||||
-rw-r--r-- | test/files/pos/sammy_twice.flags | 1 | ||||
-rw-r--r-- | test/files/pos/sammy_twice.scala | 9 | ||||
-rw-r--r-- | test/files/pos/t6221.scala | 8 |
7 files changed, 32 insertions, 2 deletions
diff --git a/test/files/pos/sammy_poly.flags b/test/files/pos/sammy_poly.flags new file mode 100644 index 0000000000..48fd867160 --- /dev/null +++ b/test/files/pos/sammy_poly.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/test/files/pos/sammy_poly.scala b/test/files/pos/sammy_poly.scala new file mode 100644 index 0000000000..f03be4f8f5 --- /dev/null +++ b/test/files/pos/sammy_poly.scala @@ -0,0 +1,6 @@ +// test synthesizeSAMFunction where the sam type is not fully defined +class T { + trait F[T, U] { def apply(x: T): U } + def app[T, U](x: T)(f: F[T, U]): U = f(x) + app(1)(x => List(x)) +}
\ No newline at end of file diff --git a/test/files/pos/sammy_scope.flags b/test/files/pos/sammy_scope.flags new file mode 100644 index 0000000000..48fd867160 --- /dev/null +++ b/test/files/pos/sammy_scope.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/test/files/pos/sammy_scope.scala b/test/files/pos/sammy_scope.scala new file mode 100644 index 0000000000..8f1fe7058e --- /dev/null +++ b/test/files/pos/sammy_scope.scala @@ -0,0 +1,8 @@ +// test synthesizeSAMFunction: scope hygiene +abstract class SamFun[T1, R] { self => + def apply(v1: T1): R + + // this should type check, as the apply ref is equivalent to self.apply + // it shouldn't resolve to the sam's apply that's synthesized (that wouldn't type check, hence the pos test) + def compose[A](g: SamFun[A, T1]): SamFun[A, R] = { x => apply(g(x)) } +}
\ No newline at end of file diff --git a/test/files/pos/sammy_twice.flags b/test/files/pos/sammy_twice.flags new file mode 100644 index 0000000000..48fd867160 --- /dev/null +++ b/test/files/pos/sammy_twice.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/test/files/pos/sammy_twice.scala b/test/files/pos/sammy_twice.scala new file mode 100644 index 0000000000..c91f5b9fd2 --- /dev/null +++ b/test/files/pos/sammy_twice.scala @@ -0,0 +1,9 @@ +// test repeated synthesizeSAMFunction where the sam type is not fully defined +// the naive implementation would enter the same apply$body in the same scope twice +trait F[T, U] { def apply(x: T): U } + +class C { + def app[T, U](x: T)(f: F[T, U]): U = f(x) + app(1)(x => List(x)) + app(2)(x => List(x)) +}
\ No newline at end of file diff --git a/test/files/pos/t6221.scala b/test/files/pos/t6221.scala index dd7776f596..34f02859f3 100644 --- a/test/files/pos/t6221.scala +++ b/test/files/pos/t6221.scala @@ -7,23 +7,27 @@ class MyCollection[A] { class OtherFunc[-A, +B] {} object Test { - implicit def functionToMyFunc[A, B](f: A => B): MyFunc[A, B] = new MyFunc + implicit def functionToMyFunc[A, B](f: A => B): MyFunc[A, B] = new MyFunc // = new MyFunc[A,Nothing](); - implicit def otherFuncToMyFunc[A, B](f: OtherFunc[A, B]): MyFunc[A, B] = new MyFunc + implicit def otherFuncToMyFunc[A, B](f: OtherFunc[A, B]): MyFunc[A, B] = new MyFunc // = new MyFunc[A,Nothing](); def main(args: Array[String]) { val col = new MyCollection[Int] // Doesn't compile: error: missing parameter type for expanded function ((x$1) => x$1.toString) println(col.map(_.toString)) + // scala.this.Predef.println(col.map[String](Test.this.functionToMyFunc[Int, String](((x$1: Int) => x$1.toString())))); // Doesn't compile: error: missing parameter type println(col.map(x => x.toString)) + // scala.this.Predef.println(col.map[String](Test.this.functionToMyFunc[Int, String](((x: Int) => x.toString())))); // Does compile println(col.map((x: Int) => x.toString)) + // scala.this.Predef.println(col.map[String](Test.this.functionToMyFunc[Int, String](((x: Int) => x.toString())))); // Does compile (even though type params of OtherFunc not given) println(col.map(new OtherFunc)) + // scala.this.Predef.println(col.map[Nothing](Test.this.otherFuncToMyFunc[Any, Nothing](new OtherFunc[Any,Nothing]()))) } }
\ No newline at end of file |