summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/files/pos/t9479.scala15
-rw-r--r--test/files/pos/t9479b.scala15
-rw-r--r--test/files/run/reflection-fieldmirror-ctorparam.check6
-rw-r--r--test/files/run/trait-default-specialize.check3
-rw-r--r--test/files/run/trait-default-specialize.scala14
-rw-r--r--test/junit/scala/collection/mutable/BitSetTest.scala7
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala17
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/DefaultMethodTest.scala43
8 files changed, 117 insertions, 3 deletions
diff --git a/test/files/pos/t9479.scala b/test/files/pos/t9479.scala
new file mode 100644
index 0000000000..38eabf4338
--- /dev/null
+++ b/test/files/pos/t9479.scala
@@ -0,0 +1,15 @@
+trait Predefs {
+ def bridge(p: String): Unit = ???
+ def bridge(p: Any): Unit = ???
+}
+
+package object molecule extends Predefs
+
+package molecule {
+ package process {
+ class Test {
+ def main(): Unit = bridge(null, null)
+ }
+ }
+}
+
diff --git a/test/files/pos/t9479b.scala b/test/files/pos/t9479b.scala
new file mode 100644
index 0000000000..5fc795a1fd
--- /dev/null
+++ b/test/files/pos/t9479b.scala
@@ -0,0 +1,15 @@
+trait Predefs {
+ def bridge(p: String): Unit = ???
+ def bridge(p: Any): Unit = ???
+}
+
+package object molecule extends Predefs
+
+package molecule {
+ package process {
+ class Test {
+ def main(): Unit = molecule.bridge(null, null)
+ }
+ }
+}
+
diff --git a/test/files/run/reflection-fieldmirror-ctorparam.check b/test/files/run/reflection-fieldmirror-ctorparam.check
index e391e7ccfe..c66be94ed7 100644
--- a/test/files/run/reflection-fieldmirror-ctorparam.check
+++ b/test/files/run/reflection-fieldmirror-ctorparam.check
@@ -1,3 +1,3 @@
-class scala.ScalaReflectionException: Scala field x isn't represented as a Java field, neither it has a Java accessor method
-note that private parameters of class constructors don't get mapped onto fields and/or accessors,
-unless they are used outside of their declaring constructors.
+class scala.ScalaReflectionException: Scala field x of class A isn't represented as a Java field, nor does it have a
+Java accessor method. One common reason for this is that it may be a private class parameter
+not used outside the primary constructor.
diff --git a/test/files/run/trait-default-specialize.check b/test/files/run/trait-default-specialize.check
new file mode 100644
index 0000000000..1034d1c703
--- /dev/null
+++ b/test/files/run/trait-default-specialize.check
@@ -0,0 +1,3 @@
+public abstract void T.t(java.lang.Object)
+0
+0
diff --git a/test/files/run/trait-default-specialize.scala b/test/files/run/trait-default-specialize.scala
new file mode 100644
index 0000000000..6faa9d5f47
--- /dev/null
+++ b/test/files/run/trait-default-specialize.scala
@@ -0,0 +1,14 @@
+trait T[@specialized(Int) A] {
+ def t(a: A): Unit
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ class TInt extends T[Int] { def t(a : Int) = println(a) }
+ val tMethods = classOf[TInt].getInterfaces.head.getMethods.filter(_.getName == "t")
+ println(tMethods.map(_.toString).sorted.mkString("\n"))
+ new TInt().t(0)
+ def call[A](t: T[A], a: A) = t.t(a)
+ call[Int](new TInt(), 0)
+ }
+}
diff --git a/test/junit/scala/collection/mutable/BitSetTest.scala b/test/junit/scala/collection/mutable/BitSetTest.scala
index d56cc45601..e832194989 100644
--- a/test/junit/scala/collection/mutable/BitSetTest.scala
+++ b/test/junit/scala/collection/mutable/BitSetTest.scala
@@ -28,4 +28,11 @@ class BitSetTest {
littleBitSet &= bigBitSet
assert(littleBitSet.toBitMask.length < bigBitSet.toBitMask.length, "Needlessly extended the size of bitset on &=")
}
+
+ @Test def test_SI8647() {
+ val bs = BitSet()
+ bs.map(_ + 1) // Just needs to compile
+ val xs = bs: SortedSet[Int]
+ xs.map(_ + 1) // Also should compile (did before)
+ }
}
diff --git a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala
index ee9580c1c3..769236ae49 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala
@@ -93,6 +93,23 @@ object CodeGenTools {
getGeneratedClassfiles(compiler.settings.outputDirs.getSingleOutput.get)
}
+ def compileTransformed(compiler: Global)(scalaCode: String, javaCode: List[(String, String)] = Nil, beforeBackend: compiler.Tree => compiler.Tree): List[(String, Array[Byte])] = {
+ compiler.settings.stopBefore.value = "jvm" :: Nil
+ val run = newRun(compiler)
+ import compiler._
+ val scalaUnit = newCompilationUnit(scalaCode, "unitTestSource.scala")
+ val javaUnits = javaCode.map(p => newCompilationUnit(p._1, p._2))
+ val units = scalaUnit :: javaUnits
+ run.compileUnits(units, run.parserPhase)
+ compiler.settings.stopBefore.value = Nil
+ scalaUnit.body = beforeBackend(scalaUnit.body)
+ checkReport(compiler, _ => false)
+ val run1 = newRun(compiler)
+ run1.compileUnits(units, run1.phaseNamed("jvm"))
+ checkReport(compiler, _ => false)
+ getGeneratedClassfiles(compiler.settings.outputDirs.getSingleOutput.get)
+ }
+
/**
* Compile multiple Scala files separately into a single output directory.
*
diff --git a/test/junit/scala/tools/nsc/backend/jvm/DefaultMethodTest.scala b/test/junit/scala/tools/nsc/backend/jvm/DefaultMethodTest.scala
new file mode 100644
index 0000000000..f9a55bb26e
--- /dev/null
+++ b/test/junit/scala/tools/nsc/backend/jvm/DefaultMethodTest.scala
@@ -0,0 +1,43 @@
+package scala.tools.nsc.backend.jvm
+
+import org.junit.Assert._
+import org.junit.Test
+
+import scala.collection.JavaConverters
+import scala.tools.asm.Opcodes
+import scala.tools.asm.tree.ClassNode
+import scala.tools.nsc.backend.jvm.CodeGenTools._
+import JavaConverters._
+import scala.tools.testing.ClearAfterClass
+
+object DefaultMethodTest extends ClearAfterClass.Clearable {
+ var compiler = newCompiler(extraArgs = "-Ybackend:GenBCode")
+ def clear(): Unit = { compiler = null }
+}
+
+class DefaultMethodTest extends ClearAfterClass {
+ ClearAfterClass.stateToClear = DirectCompileTest
+ val compiler = DirectCompileTest.compiler
+
+ @Test
+ def defaultMethodsViaGenBCode(): Unit = {
+ import compiler._
+ val code = "package pack { trait T { def foo: Int }}"
+ object makeFooDefaultMethod extends Transformer {
+ val Foo = TermName("foo")
+ /** Transforms a single tree. */
+ override def transform(tree: compiler.Tree): compiler.Tree = tree match {
+ case dd @ DefDef(_, Foo, _, _, _, _) =>
+ dd.symbol.setFlag(reflect.internal.Flags.JAVA_DEFAULTMETHOD)
+ copyDefDef(dd)(rhs = Literal(Constant(1)).setType(definitions.IntTpe))
+ case _ => super.transform(tree)
+ }
+ }
+ val asmClasses: List[ClassNode] = readAsmClasses(compileTransformed(compiler)(code, Nil, makeFooDefaultMethod.transform(_)))
+ val foo = asmClasses.head.methods.iterator.asScala.toList.last
+ assertTrue("default method should not be abstract", (foo.access & Opcodes.ACC_ABSTRACT) == 0)
+ assertTrue("default method body emitted", foo.instructions.size() > 0)
+ }
+
+
+}