diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-03-17 11:56:14 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-03-26 22:54:10 -0700 |
commit | f922f367d58b3ba6bbb4cb0864ce82c5cd6f7966 (patch) | |
tree | 18a9cf588cd9e6dbe0a3815258f4dede2af3c772 /test/files/pos | |
parent | 040c0434d456dd75a174147d8a0c4cab37266ba6 (diff) | |
download | scala-f922f367d58b3ba6bbb4cb0864ce82c5cd6f7966.tar.gz scala-f922f367d58b3ba6bbb4cb0864ce82c5cd6f7966.tar.bz2 scala-f922f367d58b3ba6bbb4cb0864ce82c5cd6f7966.zip |
Additional SAM restrictions identified by Jason
Also test roundtripping serialization of a lambda that targets a
SAM that's not FunctionN (it should make no difference).
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/sammy_implicit.scala | 3 | ||||
-rw-r--r-- | test/files/pos/sammy_overload.scala | 27 | ||||
-rw-r--r-- | test/files/pos/sammy_poly.scala | 12 | ||||
-rw-r--r-- | test/files/pos/sammy_scope.scala | 4 |
4 files changed, 38 insertions, 8 deletions
diff --git a/test/files/pos/sammy_implicit.scala b/test/files/pos/sammy_implicit.scala index e4b82df4cc..ab63fc729e 100644 --- a/test/files/pos/sammy_implicit.scala +++ b/test/files/pos/sammy_implicit.scala @@ -1,5 +1,6 @@ +trait Fun[A, B] { def apply(a: A): B } + abstract class SamImplicitConvert { - trait Fun[A, B] { def apply(a: A): B } class Lst[T] abstract class Str { def getBytes: Array[Int] } def flatMap[B](f: Fun[Str, Lst[B]]): List[B] = ??? diff --git a/test/files/pos/sammy_overload.scala b/test/files/pos/sammy_overload.scala index 5472248f4d..6a3c88ec55 100644 --- a/test/files/pos/sammy_overload.scala +++ b/test/files/pos/sammy_overload.scala @@ -6,4 +6,29 @@ object Test { def foo(x: String): Unit = ??? def foo(): Unit = ??? val f: Consumer[_ >: String] = foo -}
\ No newline at end of file +} + +trait A[A, B] { def apply(a: A): B } + +class ArityDisambiguate { + object O { + def m(a: A[Int, Int]) = 0 + def m(f: (Int, Int) => Int) = 1 + } + + O.m(x => x) // ok + O.m((x, y) => x) // ok +} + +class InteractionWithImplicits { + object O { + class Ev + implicit object E1 extends Ev + implicit object E2 extends Ev + def m(a: A[Int, Int])(implicit ol: E1.type) = 0 + def m(a: A[String, Int])(implicit ol: E2.type) = 1 + } + + O.m((x: Int) => 1) // ok + O.m((x: String) => 1) // ok +} diff --git a/test/files/pos/sammy_poly.scala b/test/files/pos/sammy_poly.scala index 75ee36f654..ba10baea49 100644 --- a/test/files/pos/sammy_poly.scala +++ b/test/files/pos/sammy_poly.scala @@ -1,8 +1,12 @@ // test synthesizeSAMFunction where the sam type is not fully defined -class T { - trait F[T, U] { def apply(x: T): U } -// type F[T, U] = T => U - // NOTE: the f(x) desugaring for now assumes the single abstract method is called 'apply' +trait F[T, R]{ def apply(x: T): R } + +class PolySammy { + (x => x + 1): F[Int, Int] + ((x: Int) => x + 1): F[Int, Int] + ((x: String) => 1): F[String, Int] + ((x: Object) => 1): F[String, Int] + def app[T, U](x: T)(f: F[T, U]): U = f(x) app(1)(x => List(x)) } diff --git a/test/files/pos/sammy_scope.scala b/test/files/pos/sammy_scope.scala index 8f1fe7058e..9d35501a47 100644 --- a/test/files/pos/sammy_scope.scala +++ b/test/files/pos/sammy_scope.scala @@ -1,8 +1,8 @@ // test synthesizeSAMFunction: scope hygiene -abstract class SamFun[T1, R] { self => +trait 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 +} |