diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/jvm/annotations.check | 3 | ||||
-rw-r--r-- | test/files/jvm/annotations.flags | 1 | ||||
-rw-r--r-- | test/files/neg/sammy_restrictions.check | 33 | ||||
-rw-r--r-- | test/files/neg/sammy_restrictions.scala | 7 | ||||
-rw-r--r-- | test/files/pos/t482.scala | 7 | ||||
-rw-r--r-- | test/files/pos/t4914.scala | 20 | ||||
-rw-r--r-- | test/files/run/lambda-serialization.scala | 2 | ||||
-rw-r--r-- | test/files/run/sammy_seriazable.scala | 47 | ||||
-rw-r--r-- | test/files/run/t7439.check | 2 | ||||
-rw-r--r-- | test/files/run/t8442.check | 2 | ||||
-rw-r--r-- | test/files/run/t9268.check | 3 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala | 19 |
12 files changed, 129 insertions, 17 deletions
diff --git a/test/files/jvm/annotations.check b/test/files/jvm/annotations.check index a8dc5ecdd1..43f85ca199 100644 --- a/test/files/jvm/annotations.check +++ b/test/files/jvm/annotations.check @@ -1,3 +1,6 @@ +annotations.scala:7: warning: class remote in package scala is deprecated (since 2.12.0): extend java.rmi.Remote instead and add @throws[java.rmi.RemoteException] to public methods + def foo: Unit = () + ^ class java.rmi.RemoteException class java.io.IOException @java.lang.Deprecated() diff --git a/test/files/jvm/annotations.flags b/test/files/jvm/annotations.flags new file mode 100644 index 0000000000..c36e713ab8 --- /dev/null +++ b/test/files/jvm/annotations.flags @@ -0,0 +1 @@ +-deprecation
\ No newline at end of file diff --git a/test/files/neg/sammy_restrictions.check b/test/files/neg/sammy_restrictions.check index 09579cbe21..0225c61ac1 100644 --- a/test/files/neg/sammy_restrictions.check +++ b/test/files/neg/sammy_restrictions.check @@ -1,51 +1,62 @@ -sammy_restrictions.scala:35: error: type mismatch; +sammy_restrictions.scala:38: error: type mismatch; found : () => Int required: NoAbstract (() => 0) : NoAbstract ^ -sammy_restrictions.scala:36: error: type mismatch; +sammy_restrictions.scala:39: error: type mismatch; found : Int => Int required: TwoAbstract ((x: Int) => 0): TwoAbstract ^ -sammy_restrictions.scala:37: error: type mismatch; +sammy_restrictions.scala:40: error: type mismatch; found : Int => Int required: NoEmptyConstructor ((x: Int) => 0): NoEmptyConstructor ^ -sammy_restrictions.scala:38: error: type mismatch; +sammy_restrictions.scala:41: error: type mismatch; found : Int => Int required: MultipleConstructorLists ((x: Int) => 0): MultipleConstructorLists ^ -sammy_restrictions.scala:39: error: type mismatch; +sammy_restrictions.scala:42: 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; +sammy_restrictions.scala:43: error: type mismatch; found : Int => Int required: MultipleMethodLists ((x: Int) => 0): MultipleMethodLists ^ -sammy_restrictions.scala:41: error: type mismatch; +sammy_restrictions.scala:44: error: type mismatch; found : Int => Int required: ImplicitConstructorParam ((x: Int) => 0): ImplicitConstructorParam ^ -sammy_restrictions.scala:42: error: type mismatch; +sammy_restrictions.scala:45: error: type mismatch; found : Int => Int required: ImplicitMethodParam ((x: Int) => 0): ImplicitMethodParam ^ -sammy_restrictions.scala:43: error: type mismatch; +sammy_restrictions.scala:46: error: type mismatch; found : Int => Int required: PolyMethod ((x: Int) => 0): PolyMethod ^ -sammy_restrictions.scala:44: error: type mismatch; +sammy_restrictions.scala:47: error: type mismatch; found : Int => Int required: SelfTp ((x: Int) => 0): SelfTp ^ -10 errors found +sammy_restrictions.scala:48: error: type mismatch; + found : Int => Int + required: T1 with U1 + ((x: Int) => 0): T1 with U1 + ^ +sammy_restrictions.scala:49: error: type mismatch; + found : Int => Int + required: Test.NonClassTypeRefinement + (which expands to) DerivedOneAbstract with OneAbstract + ((x: Int) => 0): NonClassTypeRefinement + ^ +12 errors found diff --git a/test/files/neg/sammy_restrictions.scala b/test/files/neg/sammy_restrictions.scala index ff2c16b679..dee4f1f247 100644 --- a/test/files/neg/sammy_restrictions.scala +++ b/test/files/neg/sammy_restrictions.scala @@ -27,9 +27,12 @@ abstract class DerivedOneAbstract extends OneAbstract abstract class SelfTp { self: NoAbstract => def ap(a: Int): Any } abstract class SelfVar { self => def ap(a: Int): Any } +trait T1 { def t(a: Int): Int }; trait U1 + object Test { implicit val s: String = "" - type NonClassType = DerivedOneAbstract with OneAbstract + type NonClassTypeRefinement = DerivedOneAbstract with OneAbstract + type NonClassType = DerivedOneAbstract // errors: (() => 0) : NoAbstract @@ -42,6 +45,8 @@ object Test { ((x: Int) => 0): ImplicitMethodParam ((x: Int) => 0): PolyMethod ((x: Int) => 0): SelfTp + ((x: Int) => 0): T1 with U1 + ((x: Int) => 0): NonClassTypeRefinement // allowed: ((x: Int) => 0): OneEmptyConstructor diff --git a/test/files/pos/t482.scala b/test/files/pos/t482.scala new file mode 100644 index 0000000000..b121c93337 --- /dev/null +++ b/test/files/pos/t482.scala @@ -0,0 +1,7 @@ +object Test { + class Foo { val z = "foo"; val y : z.type = z } + + val x : ({ val y : z.type } forSome { val z : String }) = new Foo + + val x2 : ({ val y : T } forSome { type T <: String with Singleton }) = new Foo +} diff --git a/test/files/pos/t4914.scala b/test/files/pos/t4914.scala new file mode 100644 index 0000000000..a6c8ef5a4e --- /dev/null +++ b/test/files/pos/t4914.scala @@ -0,0 +1,20 @@ +trait Type { + type S +} + +class ConcreteType extends Type { + type S = Double +} + +trait Base { + type T <: Type + val m: Map[t#S, t#S] forSome { type t <: T with Singleton } + val n: Map[x.type#S, x.type#S] forSome { val x: T } +} + +abstract class Derived extends Base { + override type T = ConcreteType + override val m = Map[Double, Double]() + /** This does not work. ยง3.2.10 indicates that types n is shorthand for type of m. */ + override val n = Map[Double, Double]() +} diff --git a/test/files/run/lambda-serialization.scala b/test/files/run/lambda-serialization.scala index 0eee1193d7..08e235b1cb 100644 --- a/test/files/run/lambda-serialization.scala +++ b/test/files/run/lambda-serialization.scala @@ -1,6 +1,6 @@ import java.io.{ByteArrayInputStream, ObjectInputStream, ObjectOutputStream, ByteArrayOutputStream} -trait IntToString { def apply(i: Int): String } +trait IntToString extends java.io.Serializable { def apply(i: Int): String } object Test { def main(args: Array[String]): Unit = { diff --git a/test/files/run/sammy_seriazable.scala b/test/files/run/sammy_seriazable.scala new file mode 100644 index 0000000000..458b99238a --- /dev/null +++ b/test/files/run/sammy_seriazable.scala @@ -0,0 +1,47 @@ +import java.io._ + +trait NotSerializableInterface { def apply(a: Any): Any } +abstract class NotSerializableClass { def apply(a: Any): Any } +// SAM type that supports lambdas-as-invoke-dynamic +trait IsSerializableInterface extends java.io.Serializable { def apply(a: Any): Any } +// SAM type that still requires lambdas-as-anonhmous-classes +abstract class IsSerializableClass extends java.io.Serializable { def apply(a: Any): Any } + +object Test { + def main(args: Array[String]) { + val nsi: NotSerializableInterface = x => x + val nsc: NotSerializableClass = x => x + + import SerDes._ + assertNotSerializable(nsi) + assertNotSerializable(nsc) + assert(serializeDeserialize[IsSerializableInterface](x => x).apply("foo") == "foo") + assert(serializeDeserialize[IsSerializableClass](x => x).apply("foo") == "foo") + assert(ObjectStreamClass.lookup(((x => x): IsSerializableClass).getClass).getSerialVersionUID == 0) + } +} + +object SerDes { + def assertNotSerializable(a: AnyRef): Unit = { + try { + serialize(a) + assert(false) + } catch { + case _: NotSerializableException => // okay + } + } + + def serialize(obj: AnyRef): Array[Byte] = { + val buffer = new ByteArrayOutputStream + val out = new ObjectOutputStream(buffer) + out.writeObject(obj) + buffer.toByteArray + } + + def deserialize(a: Array[Byte]): AnyRef = { + val in = new ObjectInputStream(new ByteArrayInputStream(a)) + in.readObject + } + + def serializeDeserialize[T <: AnyRef](obj: T) = deserialize(serialize(obj)).asInstanceOf[T] +} diff --git a/test/files/run/t7439.check b/test/files/run/t7439.check index 9ea09f9c40..b95884311a 100644 --- a/test/files/run/t7439.check +++ b/test/files/run/t7439.check @@ -1,2 +1,2 @@ Recompiling after deleting t7439-run.obj/A_1.class -pos: NoPosition Class A_1 not found - continuing with a stub. WARNING + diff --git a/test/files/run/t8442.check b/test/files/run/t8442.check index ce9e8b52ff..8b13789179 100644 --- a/test/files/run/t8442.check +++ b/test/files/run/t8442.check @@ -1 +1 @@ -pos: NoPosition Class A_1 not found - continuing with a stub. WARNING + diff --git a/test/files/run/t9268.check b/test/files/run/t9268.check index 90ef940eb3..60afcbb648 100644 --- a/test/files/run/t9268.check +++ b/test/files/run/t9268.check @@ -1,5 +1,4 @@ Compiling Client1 -pos: NoPosition Class Waiter not found - continuing with a stub. WARNING + Compiling Client2 -pos: NoPosition Class Waiter not found - continuing with a stub. WARNING pos: NoPosition Unable to locate class corresponding to inner class entry for Predicate in owner Waiter ERROR diff --git a/test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala b/test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala index b2ee8b3a45..5904cb2441 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala @@ -168,4 +168,23 @@ class BytecodeTest extends BytecodeTesting { assertEquals(x.start, labels(1)) assertEquals(x.end, labels(7)) } + + @Test // wrong line numbers for rewritten `this` references in trait static methods + def sd186_traitLineNumber(): Unit = { + val code = + """trait T { + | def t(): Unit = { + | toString + | toString + | } + |} + """.stripMargin + val t = compileClass(code) + val tMethod = getMethod(t, "t$") + val invoke = Invoke(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false) + assertSameCode(tMethod.instructions, + List(Label(0), LineNumber(3, Label(0)), VarOp(ALOAD, 0), invoke, Op(POP), + Label(5), LineNumber(4, Label(5)), VarOp(ALOAD, 0), invoke, Op(POP), Op(RETURN), Label(11)) + ) + } } |