summaryrefslogtreecommitdiff
path: root/test/files/neg
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2016-03-23 10:52:57 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2016-03-26 22:55:10 -0700
commit608ac2c2b9e3f6f46489e20830d8949ee7d506cf (patch)
tree8d995139a8a66f56fed90bf65f7ece5bf26d55d7 /test/files/neg
parent878e20a5243383300d3b4990146d260409bf5dfd (diff)
downloadscala-608ac2c2b9e3f6f46489e20830d8949ee7d506cf.tar.gz
scala-608ac2c2b9e3f6f46489e20830d8949ee7d506cf.tar.bz2
scala-608ac2c2b9e3f6f46489e20830d8949ee7d506cf.zip
Soften sam restrictions
Some of the earlier proposals were too strongly linked to the requirements of the Java 8 platform, which was problematic for scala.js & friends. Instead of ruling out SAM types that we can't compile to use LambdaMetaFactory, expand those during compilation to anonymous subclasses, instead of invokedynamic + LMF. Also, self types rear their ugly heads again. Align `hasSelfType` with the implementation suggested in `thisSym`'s docs.
Diffstat (limited to 'test/files/neg')
-rw-r--r--test/files/neg/sammy_restrictions.check58
-rw-r--r--test/files/neg/sammy_restrictions.scala64
2 files changed, 68 insertions, 54 deletions
diff --git a/test/files/neg/sammy_restrictions.check b/test/files/neg/sammy_restrictions.check
index 5fd2c858c2..09579cbe21 100644
--- a/test/files/neg/sammy_restrictions.check
+++ b/test/files/neg/sammy_restrictions.check
@@ -1,37 +1,51 @@
-sammy_restrictions.scala:37: error: type mismatch;
+sammy_restrictions.scala:35: error: type mismatch;
found : () => Int
required: NoAbstract
- (() => 0) : NoAbstract // error expected
+ (() => 0) : NoAbstract
^
-sammy_restrictions.scala:38: error: type mismatch;
+sammy_restrictions.scala:36: error: type mismatch;
found : Int => Int
required: TwoAbstract
- ((x: Int) => 0): TwoAbstract // error expected
+ ((x: Int) => 0): TwoAbstract
^
-sammy_restrictions.scala:41: error: type mismatch;
+sammy_restrictions.scala:37: error: type mismatch;
+ found : Int => Int
+ required: NoEmptyConstructor
+ ((x: Int) => 0): NoEmptyConstructor
+ ^
+sammy_restrictions.scala:38: error: type mismatch;
+ found : Int => Int
+ required: MultipleConstructorLists
+ ((x: Int) => 0): MultipleConstructorLists
+ ^
+sammy_restrictions.scala:39: error: type mismatch;
+ found : Int => Int
+ required: OneEmptySecondaryConstructor
+ ((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call.
+ ^
+sammy_restrictions.scala:40: error: type mismatch;
found : Int => Int
required: MultipleMethodLists
- ((x: Int) => 0): MultipleMethodLists // error expected
+ ((x: Int) => 0): MultipleMethodLists
+ ^
+sammy_restrictions.scala:41: error: type mismatch;
+ found : Int => Int
+ required: ImplicitConstructorParam
+ ((x: Int) => 0): ImplicitConstructorParam
^
sammy_restrictions.scala:42: error: type mismatch;
found : Int => Int
required: ImplicitMethodParam
- ((x: Int) => 0): ImplicitMethodParam // error expected
+ ((x: Int) => 0): ImplicitMethodParam
^
-sammy_restrictions.scala:45: error: type mismatch;
+sammy_restrictions.scala:43: error: type mismatch;
found : Int => Int
required: PolyMethod
- ((x: Int) => 0): PolyMethod // error expected
- ^
-sammy_restrictions.scala:47: error: missing parameter type
- (x => x + 1): NotAnInterface[Int, Int] // error expected (not an interface)
- ^
-sammy_restrictions.scala:48: error: type mismatch;
- found : String => Int
- required: A[Object,Int]
- ((x: String) => 1): A[Object, Int] // error expected (type mismatch)
- ^
-sammy_restrictions.scala:51: error: missing parameter type
- 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)
- ^
-8 errors found
+ ((x: Int) => 0): PolyMethod
+ ^
+sammy_restrictions.scala:44: error: type mismatch;
+ found : Int => Int
+ required: SelfTp
+ ((x: Int) => 0): SelfTp
+ ^
+10 errors found
diff --git a/test/files/neg/sammy_restrictions.scala b/test/files/neg/sammy_restrictions.scala
index ed8cf35aa4..ff2c16b679 100644
--- a/test/files/neg/sammy_restrictions.scala
+++ b/test/files/neg/sammy_restrictions.scala
@@ -1,52 +1,52 @@
-trait NoAbstract
+abstract class NoAbstract
-trait TwoAbstract { def ap(a: Int): Int; def pa(a: Int): Int }
+abstract class TwoAbstract { def ap(a: Int): Int; def pa(a: Int): Int }
-trait Base // check that the super class constructor isn't considered.
+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 MultipleMethodLists { def ap(a: Int)(): Int }
+abstract class OneEmptyConstructor() { def this(a: Int) = this(); def ap(a: Int): Int }
-trait ImplicitMethodParam { def ap(a: Int)(implicit b: String): Int }
+abstract class OneEmptySecondaryConstructor(a: Int) { def this() = this(0); def ap(a: Int): Int }
-trait PolyClass[T] { def ap(a: T): T }
+abstract class MultipleConstructorLists()() { def ap(a: Int): Int }
-trait PolyMethod { def ap[T](a: T): T }
+abstract class MultipleMethodLists()() { def ap(a: Int)(): Int }
-trait OneAbstract { def ap(a: Int): Any }
-trait DerivedOneAbstract extends OneAbstract
+abstract class ImplicitConstructorParam()(implicit a: String) { def ap(a: Int): Int }
-// restrictions
+abstract class ImplicitMethodParam() { def ap(a: Int)(implicit b: String): Int }
-// must be an interface
-abstract class NotAnInterface[T, R]{ def apply(x: T): R }
+abstract class PolyClass[T] { def ap(a: T): T }
-trait A[T, R]{ def apply(x: T): R }
+abstract class PolyMethod { def ap[T](a: T): T }
-// 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
+abstract class SelfTp { self: NoAbstract => def ap(a: Int): Any }
+abstract class SelfVar { self => def ap(a: Int): Any }
object Test {
implicit val s: String = ""
type NonClassType = DerivedOneAbstract with OneAbstract
- (() => 0) : NoAbstract // error expected
- ((x: Int) => 0): TwoAbstract // error expected
+ // errors:
+ (() => 0) : NoAbstract
+ ((x: Int) => 0): TwoAbstract
+ ((x: Int) => 0): NoEmptyConstructor
+ ((x: Int) => 0): MultipleConstructorLists
+ ((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call.
+ ((x: Int) => 0): MultipleMethodLists
+ ((x: Int) => 0): ImplicitConstructorParam
+ ((x: Int) => 0): ImplicitMethodParam
+ ((x: Int) => 0): PolyMethod
+ ((x: Int) => 0): SelfTp
+
+ // allowed:
+ ((x: Int) => 0): OneEmptyConstructor
((x: Int) => 0): DerivedOneAbstract
- ((x: Int) => 0): NonClassType
- ((x: Int) => 0): MultipleMethodLists // error expected
- ((x: Int) => 0): ImplicitMethodParam // error expected
-
+ ((x: Int) => 0): NonClassType // we also allow type aliases in instantiation expressions, if they resolve to a class type
((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)
+ ((x: Int) => 0): SelfVar
}