summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-07-27 13:31:32 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-07-27 13:31:32 +1000
commitf2d7838d904572b3dd15a9ef223ecfd1a6e14697 (patch)
tree20d04ea95d60d936f0e48c9767e50e869704d68a /test
parent4c6dcfe9341d2db47a0b0a567f5646fb9d573020 (diff)
parent241bb9ac192f13868436d9a4e2e7ae29a2e22bed (diff)
downloadscala-f2d7838d904572b3dd15a9ef223ecfd1a6e14697.tar.gz
scala-f2d7838d904572b3dd15a9ef223ecfd1a6e14697.tar.bz2
scala-f2d7838d904572b3dd15a9ef223ecfd1a6e14697.zip
Merge pull request #4657 from lrytz/backports
backports from 2.12.x
Diffstat (limited to 'test')
-rw-r--r--test/files/jvm/innerClassAttribute/Test.scala4
-rw-r--r--test/files/neg/t6013/Base.java2
-rw-r--r--test/files/pos/t9392/client_2.scala4
-rw-r--r--test/files/pos/t9392/macro_1.scala16
-rw-r--r--test/files/pos/t9393/NamedImpl_1.java15
-rw-r--r--test/files/pos/t9393/NamedImpl_2.java15
-rw-r--r--test/files/pos/t9393/Named_1.java3
-rw-r--r--test/files/pos/t9393/Named_2.java3
-rw-r--r--test/files/pos/t9393/test_2.scala4
-rw-r--r--test/files/run/scalapInvokedynamic.check5
-rw-r--r--test/files/run/scalapInvokedynamic.scala11
-rw-r--r--test/files/run/t9387.scala20
-rw-r--r--test/files/run/t9387b.check1
-rw-r--r--test/files/run/t9387b.scala16
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/analysis/ProdConsAnalyzerTest.scala42
-rw-r--r--test/junit/scala/tools/nsc/symtab/FlagsTest.scala89
16 files changed, 246 insertions, 4 deletions
diff --git a/test/files/jvm/innerClassAttribute/Test.scala b/test/files/jvm/innerClassAttribute/Test.scala
index 376b3c895b..3a6737ca46 100644
--- a/test/files/jvm/innerClassAttribute/Test.scala
+++ b/test/files/jvm/innerClassAttribute/Test.scala
@@ -149,9 +149,7 @@ object Test extends BytecodeTest {
def testA11() = {
val List(ann) = innerClassNodes("A11")
- // in the java class file, the INNERCLASS attribute has more flags (public | static | abstract | interface | annotation)
- // the scala compiler has its own interpretation of java annotations ant their flags.. it only emits publicStatic.
- assertMember(ann, "JavaAnnot_1", "Ann", flags = publicStatic)
+ assertMember(ann, "JavaAnnot_1", "Ann", flags = publicAbstractInterface | Flags.ACC_STATIC | Flags.ACC_ANNOTATION)
}
def testA13() = {
diff --git a/test/files/neg/t6013/Base.java b/test/files/neg/t6013/Base.java
index b73d7fd821..ce6ee47e64 100644
--- a/test/files/neg/t6013/Base.java
+++ b/test/files/neg/t6013/Base.java
@@ -2,7 +2,7 @@ abstract public class Base {
// This must considered to be overridden by Abstract#foo based
// on the erased signatures. This special case is handled by
// `javaErasedOverridingSym` in `RefChecks`.
- public abstract void bar(java.util.List<java.lang.String> foo) { return; }
+ public void bar(java.util.List<java.lang.String> foo) { return; }
// But, a concrete method in a Java superclass must not excuse
// a deferred method in the Java subclass!
diff --git a/test/files/pos/t9392/client_2.scala b/test/files/pos/t9392/client_2.scala
new file mode 100644
index 0000000000..6b706fea12
--- /dev/null
+++ b/test/files/pos/t9392/client_2.scala
@@ -0,0 +1,4 @@
+class Client {
+ Macro()
+}
+
diff --git a/test/files/pos/t9392/macro_1.scala b/test/files/pos/t9392/macro_1.scala
new file mode 100644
index 0000000000..3f67ac17b2
--- /dev/null
+++ b/test/files/pos/t9392/macro_1.scala
@@ -0,0 +1,16 @@
+import language.experimental.macros
+
+
+object Macro {
+
+ import reflect.macros.blackbox.Context
+ def impl(c: Context)(): c.Tree = {
+ import c.universe._
+ val tree = q"""class C; new C"""
+ val tree1 = c.typecheck(tree)
+ val tpe = tree1.tpe
+ val tree2 = c.typecheck(c.untypecheck(tree1))
+ q"""$tree2.asInstanceOf[$tpe]"""
+ }
+ def apply(): Any = macro impl
+}
diff --git a/test/files/pos/t9393/NamedImpl_1.java b/test/files/pos/t9393/NamedImpl_1.java
new file mode 100644
index 0000000000..02ec9b4671
--- /dev/null
+++ b/test/files/pos/t9393/NamedImpl_1.java
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
+ */
+package bug;
+
+import bug.Named_1;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+
+public class NamedImpl_1 implements Named_1 {
+
+ public Class<? extends Annotation> annotationType() {
+ return null;
+ }
+}
diff --git a/test/files/pos/t9393/NamedImpl_2.java b/test/files/pos/t9393/NamedImpl_2.java
new file mode 100644
index 0000000000..c87e94016d
--- /dev/null
+++ b/test/files/pos/t9393/NamedImpl_2.java
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
+ */
+package bug;
+
+import bug.Named_2;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+
+public class NamedImpl_2 implements Named_2 {
+
+ public Class<? extends Annotation> annotationType() {
+ return null;
+ }
+}
diff --git a/test/files/pos/t9393/Named_1.java b/test/files/pos/t9393/Named_1.java
new file mode 100644
index 0000000000..30a6c9839a
--- /dev/null
+++ b/test/files/pos/t9393/Named_1.java
@@ -0,0 +1,3 @@
+package bug;
+
+public @interface Named_1 {}
diff --git a/test/files/pos/t9393/Named_2.java b/test/files/pos/t9393/Named_2.java
new file mode 100644
index 0000000000..3210fb636a
--- /dev/null
+++ b/test/files/pos/t9393/Named_2.java
@@ -0,0 +1,3 @@
+package bug;
+
+public @interface Named_2 {}
diff --git a/test/files/pos/t9393/test_2.scala b/test/files/pos/t9393/test_2.scala
new file mode 100644
index 0000000000..8ea346129d
--- /dev/null
+++ b/test/files/pos/t9393/test_2.scala
@@ -0,0 +1,4 @@
+class C {
+ new bug.NamedImpl_1 // separate compilation, testing the classfile parser
+ new bug.NamedImpl_2 // mixed compilation, testing the java source parser
+}
diff --git a/test/files/run/scalapInvokedynamic.check b/test/files/run/scalapInvokedynamic.check
new file mode 100644
index 0000000000..8e4b08f234
--- /dev/null
+++ b/test/files/run/scalapInvokedynamic.check
@@ -0,0 +1,5 @@
+class C extends scala.AnyRef {
+ def this() = { /* compiled code */ }
+ def m: java.lang.String = { /* compiled code */ }
+}
+
diff --git a/test/files/run/scalapInvokedynamic.scala b/test/files/run/scalapInvokedynamic.scala
new file mode 100644
index 0000000000..670cf26662
--- /dev/null
+++ b/test/files/run/scalapInvokedynamic.scala
@@ -0,0 +1,11 @@
+class C {
+ def m = {
+ val f = (x: String) => x.trim
+ f(" H ae i ")
+ }
+}
+
+object Test extends App {
+ val testClassesDir = System.getProperty("partest.output")
+ scala.tools.scalap.Main.main(Array("-cp", testClassesDir, "C"))
+} \ No newline at end of file
diff --git a/test/files/run/t9387.scala b/test/files/run/t9387.scala
new file mode 100644
index 0000000000..3e33d19fd2
--- /dev/null
+++ b/test/files/run/t9387.scala
@@ -0,0 +1,20 @@
+class G[T]
+object G {
+ def v[T](x: T): G[T] = null
+}
+
+class A[T]
+object A {
+ def apply[T](x: => G[T]): A[T] = null
+}
+
+object T {
+ A[Unit](G.v(() => ())) // Was VerifyError
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ T
+ }
+
+} \ No newline at end of file
diff --git a/test/files/run/t9387b.check b/test/files/run/t9387b.check
new file mode 100644
index 0000000000..6a452c185a
--- /dev/null
+++ b/test/files/run/t9387b.check
@@ -0,0 +1 @@
+()
diff --git a/test/files/run/t9387b.scala b/test/files/run/t9387b.scala
new file mode 100644
index 0000000000..6339f4caba
--- /dev/null
+++ b/test/files/run/t9387b.scala
@@ -0,0 +1,16 @@
+object T {
+ val f: Unit = () => ()
+ println(f)
+}
+
+object U {
+ def f[T](t: T): T = t
+ f[Unit](() => ())
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ T
+ U
+ }
+}
diff --git a/test/junit/scala/tools/nsc/backend/jvm/analysis/ProdConsAnalyzerTest.scala b/test/junit/scala/tools/nsc/backend/jvm/analysis/ProdConsAnalyzerTest.scala
index 9af9ef54fc..a5b3faced8 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/analysis/ProdConsAnalyzerTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/analysis/ProdConsAnalyzerTest.scala
@@ -246,4 +246,46 @@ class ProdConsAnalyzerTest extends ClearAfterClass {
testSingleInsn(a.consumersOfOutputsFrom(l2i), "IRETURN")
testSingleInsn(a.producersForInputsOf(ret), "L2I")
}
+
+ @Test
+ def cyclicProdCons(): Unit = {
+ import Opcodes._
+ val m = genMethod(descriptor = "(I)I")(
+ Label(1),
+ VarOp(ILOAD, 1),
+ IntOp(BIPUSH, 10),
+ Op(IADD), // consumer of the above ILOAD
+
+ Op(ICONST_0),
+ Jump(IF_ICMPNE, Label(2)),
+
+ VarOp(ILOAD, 1),
+ VarOp(ISTORE, 1),
+ Jump(GOTO, Label(1)),
+
+ Label(2),
+ IntOp(BIPUSH, 9),
+ Op(IRETURN)
+ )
+ m.maxLocals = 2
+ m.maxStack = 2
+ val a = new ProdConsAnalyzer(m, "C")
+
+ val List(iadd) = findInstr(m, "IADD")
+ val firstLoad = iadd.getPrevious.getPrevious
+ assert(firstLoad.getOpcode == ILOAD)
+ val secondLoad = findInstr(m, "ISTORE").head.getPrevious
+ assert(secondLoad.getOpcode == ILOAD)
+
+ testSingleInsn(a.producersForValueAt(iadd, 2), "ILOAD")
+ testSingleInsn(a.initialProducersForValueAt(iadd, 2), "ParameterProducer(1)")
+ testMultiInsns(a.producersForInputsOf(firstLoad), List("ParameterProducer", "ISTORE"))
+ testMultiInsns(a.producersForInputsOf(secondLoad), List("ParameterProducer", "ISTORE"))
+
+ testSingleInsn(a.ultimateConsumersOfOutputsFrom(firstLoad), "IADD")
+ testSingleInsn(a.ultimateConsumersOfOutputsFrom(secondLoad), "IADD")
+
+ testSingleInsn(a.consumersOfOutputsFrom(firstLoad), "IADD")
+ testSingleInsn(a.consumersOfOutputsFrom(secondLoad), "ISTORE")
+ }
}
diff --git a/test/junit/scala/tools/nsc/symtab/FlagsTest.scala b/test/junit/scala/tools/nsc/symtab/FlagsTest.scala
new file mode 100644
index 0000000000..fc0e8b0f6b
--- /dev/null
+++ b/test/junit/scala/tools/nsc/symtab/FlagsTest.scala
@@ -0,0 +1,89 @@
+package scala.tools.nsc
+package symtab
+
+import org.junit.Assert._
+import scala.tools.testing.AssertUtil._
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(classOf[JUnit4])
+class FlagsTest {
+ object symbolTable extends SymbolTableForUnitTesting
+ import symbolTable._
+ import Flags._
+
+ def sym = NoSymbol.newTermSymbol(nme.EMPTY)
+
+ def withFlagMask[A](mask: Long)(body: => A): A = enteringPhase(new Phase(NoPhase) {
+ override def flagMask = mask
+ def name = ""
+ def run() = ()
+ })(body)
+
+ def testTimedFlag(flag: Long, test: Symbol => Boolean, enabling: Boolean) = {
+ assertEquals(withFlagMask(InitialFlags)(test(sym.setFlag(flag))), !enabling)
+ assertEquals(withFlagMask(InitialFlags | flag)(test(sym.setFlag(flag))), enabling)
+ }
+
+ def testLate(flag: Long, test: Symbol => Boolean) = testTimedFlag(flag, test, enabling = true)
+ def testNot(flag: Long, test: Symbol => Boolean) = testTimedFlag(flag, test, enabling = false)
+
+ @Test
+ def testTimedFlags(): Unit = {
+ testLate(lateDEFERRED, _.isDeferred)
+ testLate(lateFINAL, _.isFinal)
+ testLate(lateINTERFACE, _.isInterface)
+ testLate(lateMETHOD, _.isMethod)
+ testLate(lateMODULE, _.isModule)
+ testNot(PROTECTED | notPROTECTED, _.isProtected)
+ testNot(OVERRIDE | notOVERRIDE, _.isOverride)
+ testNot(PRIVATE | notPRIVATE, _.isPrivate)
+
+ assertFalse(withFlagMask(AllFlags)(sym.setFlag(PRIVATE | notPRIVATE).isPrivate))
+
+ assertEquals(withFlagMask(InitialFlags)(sym.setFlag(PRIVATE | notPRIVATE).flags & PRIVATE), PRIVATE)
+ assertEquals(withFlagMask(AllFlags)(sym.setFlag(PRIVATE | notPRIVATE).flags & PRIVATE), 0)
+ }
+
+ @Test
+ def normalLateOverlap(): Unit = {
+ // late flags are shifted by LateShift == 47.
+ // however, the first late flag is lateDEFERRED, which is DEFERRED << 47 == (1 << 4) << 47 == 1 << 51
+ // the flags from 1 << 47 to 1 << 50 are not late flags. this is ensured by the LateFlags mask.
+
+ for (i <- 0 to 3) {
+ val f = 1L << i
+ assertEquals(withFlagMask(AllFlags)(sym.setFlag(f << LateShift).flags & f), 0) // not treated as late flag
+ }
+ for (i <- 4 to 8) {
+ val f = 1L << i
+ assertEquals(withFlagMask(AllFlags)(sym.setFlag(f << LateShift).flags & f), f) // treated as late flag
+ }
+ }
+
+ @Test
+ def normalAnti(): Unit = {
+ for (i <- 0 to 2) {
+ val f = 1L << i
+ assertEquals(withFlagMask(AllFlags)(sym.setFlag(f | (f << AntiShift)).flags & f), 0) // negated flags
+ }
+ for (i <- 3 to 7) {
+ val f = 1L << i
+ assertEquals(withFlagMask(AllFlags)(sym.setFlag(f | (f << AntiShift)).flags & f), f) // not negated
+ }
+ }
+
+ @Test
+ def lateAntiCrossCheck(): Unit = {
+ val allButNegatable = AllFlags & ~(PROTECTED | OVERRIDE | PRIVATE)
+ val lateable = 0L | DEFERRED | FINAL | INTERFACE | METHOD | MODULE
+ val lateFlags = lateable << LateShift
+ val allButLateable = AllFlags & ~lateable
+
+ assertEquals(withFlagMask(AllFlags)(sym.setFlag(AllFlags).flags), allButNegatable)
+ assertEquals(withFlagMask(AllFlags)(sym.setFlag(allButLateable).flags), allButNegatable)
+
+ assertEquals(withFlagMask(AllFlags)(sym.setFlag(lateFlags).flags), lateFlags | lateable)
+ }
+}