summaryrefslogtreecommitdiff
path: root/test/files/neg/sammy_restrictions.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2016-03-17 11:56:14 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2016-03-26 22:54:10 -0700
commitf922f367d58b3ba6bbb4cb0864ce82c5cd6f7966 (patch)
tree18a9cf588cd9e6dbe0a3815258f4dede2af3c772 /test/files/neg/sammy_restrictions.scala
parent040c0434d456dd75a174147d8a0c4cab37266ba6 (diff)
downloadscala-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/neg/sammy_restrictions.scala')
-rw-r--r--test/files/neg/sammy_restrictions.scala63
1 files changed, 35 insertions, 28 deletions
diff --git a/test/files/neg/sammy_restrictions.scala b/test/files/neg/sammy_restrictions.scala
index 101342ad0b..ed8cf35aa4 100644
--- a/test/files/neg/sammy_restrictions.scala
+++ b/test/files/neg/sammy_restrictions.scala
@@ -1,45 +1,52 @@
-abstract class NoAbstract
+trait NoAbstract
-abstract class TwoAbstract { def ap(a: Int): Int; def pa(a: Int): Int }
+trait TwoAbstract { def ap(a: Int): Int; def pa(a: Int): Int }
-abstract class Base // check that the super class constructor isn't considered.
-abstract class NoEmptyConstructor(a: Int) extends Base { def this(a: String) = this(0); def ap(a: Int): Int }
+trait Base // check that the super class constructor isn't considered.
-abstract class OneEmptyConstructor() { def this(a: Int) = this(); def ap(a: Int): Int }
+trait MultipleMethodLists { def ap(a: Int)(): Int }
-abstract class OneEmptySecondaryConstructor(a: Int) { def this() = this(0); def ap(a: Int): Int }
+trait ImplicitMethodParam { def ap(a: Int)(implicit b: String): Int }
-abstract class MultipleConstructorLists()() { def ap(a: Int): Int }
+trait PolyClass[T] { def ap(a: T): T }
-abstract class MultipleMethodLists()() { def ap(a: Int)(): Int }
+trait PolyMethod { def ap[T](a: T): T }
-abstract class ImplicitConstructorParam()(implicit a: String) { def ap(a: Int): Int }
+trait OneAbstract { def ap(a: Int): Any }
+trait DerivedOneAbstract extends OneAbstract
-abstract class ImplicitMethodParam() { def ap(a: Int)(implicit b: String): Int }
+// restrictions
-abstract class PolyClass[T] { def ap(a: T): T }
+// must be an interface
+abstract class NotAnInterface[T, R]{ def apply(x: T): R }
-abstract class PolyMethod { def ap[T](a: T): T }
+trait A[T, R]{ def apply(x: T): R }
+
+// must not capture
+class Nested {
+ trait F[T, U] { def apply(x: T): U }
+
+ def app[T, U](x: T)(f: F[T, U]): U = f(x)
+}
-abstract class OneAbstract { def ap(a: Int): Any }
-abstract class DerivedOneAbstract extends OneAbstract
object Test {
implicit val s: String = ""
type NonClassType = DerivedOneAbstract with OneAbstract
- (() => 0) : NoAbstract
- ((x: Int) => 0): TwoAbstract
- ((x: Int) => 0): DerivedOneAbstract // okay
- ((x: Int) => 0): NonClassType // okay -- we also allow type aliases in instantiation expressions, if they resolve to a class type
- ((x: Int) => 0): NoEmptyConstructor
- ((x: Int) => 0): OneEmptyConstructor // okay
- ((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call.
- ((x: Int) => 0): MultipleConstructorLists
- ((x: Int) => 0): MultipleMethodLists
- ((x: Int) => 0): ImplicitConstructorParam
- ((x: Int) => 0): ImplicitMethodParam
-
- ((x: Int) => 0): PolyClass[Int] // okay
- ((x: Int) => 0): PolyMethod
+ (() => 0) : NoAbstract // error expected
+ ((x: Int) => 0): TwoAbstract // error expected
+ ((x: Int) => 0): DerivedOneAbstract
+ ((x: Int) => 0): NonClassType
+ ((x: Int) => 0): MultipleMethodLists // error expected
+ ((x: Int) => 0): ImplicitMethodParam // error expected
+
+ ((x: Int) => 0): PolyClass[Int]
+ ((x: Int) => 0): PolyMethod // error expected
+
+ (x => x + 1): NotAnInterface[Int, Int] // error expected (not an interface)
+ ((x: String) => 1): A[Object, Int] // error expected (type mismatch)
+
+ val n = new Nested
+ n.app(1)(x => List(x)) // error expected: n.F is not a SAM type (it does not have a no-arg ctor since it has an outer pointer)
}