diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-06-19 05:27:40 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-06-19 05:27:40 +1000 |
commit | df73cb9101953ec7cf7f2cde36c26540c7d71a9b (patch) | |
tree | 89264e3ec90f3a67714795b0168a877fa3763755 /test | |
parent | b7038a77a1e4128446dd7f863b0698d52f3ed4b7 (diff) | |
parent | 7db3a58872593526c2cc175df633161f2ce9cccb (diff) | |
download | scala-df73cb9101953ec7cf7f2cde36c26540c7d71a9b.tar.gz scala-df73cb9101953ec7cf7f2cde36c26540c7d71a9b.tar.bz2 scala-df73cb9101953ec7cf7f2cde36c26540c7d71a9b.zip |
Merge pull request #4529 from lrytz/inlineAccessibility
Fix illegal inlining of instructions accessing protected members
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/kmpSliceSearch.flags | 1 | ||||
-rw-r--r-- | test/files/run/t2106.check | 7 | ||||
-rw-r--r-- | test/files/run/t2106.flags | 2 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/opt/InlinerIllegalAccessTest.scala | 16 |
4 files changed, 19 insertions, 7 deletions
diff --git a/test/files/run/kmpSliceSearch.flags b/test/files/run/kmpSliceSearch.flags new file mode 100644 index 0000000000..ac96850b69 --- /dev/null +++ b/test/files/run/kmpSliceSearch.flags @@ -0,0 +1 @@ +-Ydelambdafy:inline
\ No newline at end of file diff --git a/test/files/run/t2106.check b/test/files/run/t2106.check index f8f625ff46..66a0e707b3 100644 --- a/test/files/run/t2106.check +++ b/test/files/run/t2106.check @@ -1,3 +1,10 @@ +#partest -Ybackend:GenBCode +t2106.scala:7: warning: A::foo()Ljava/lang/Object; is annotated @inline but could not be inlined: +The callee A::foo()Ljava/lang/Object; contains the instruction INVOKEVIRTUAL java/lang/Object.clone ()Ljava/lang/Object; +that would cause an IllegalAccessError when inlined into class Test$. + def main(args: Array[String]): Unit = x.foo + ^ +#partest !-Ybackend:GenBCode t2106.scala:7: warning: Could not inline required method foo because access level required by callee not matched by caller. def main(args: Array[String]): Unit = x.foo ^ diff --git a/test/files/run/t2106.flags b/test/files/run/t2106.flags index 00d3643fd4..a2e413bb22 100644 --- a/test/files/run/t2106.flags +++ b/test/files/run/t2106.flags @@ -1 +1 @@ --optimise -Yinline-warnings +-optimise -Yinline-warnings -Yopt:l:classpath diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerIllegalAccessTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerIllegalAccessTest.scala index b4839dcec8..7ed0e13226 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerIllegalAccessTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerIllegalAccessTest.scala @@ -32,7 +32,8 @@ class InlinerIllegalAccessTest extends ClearAfterClass { import compiler.genBCode.bTypes._ def addToRepo(cls: List[ClassNode]): Unit = for (c <- cls) byteCodeRepository.add(c, ByteCodeRepository.Classfile) - def assertEmpty(ins: Option[AbstractInsnNode]) = for (i <- ins) throw new AssertionError(textify(i)) + def assertEmpty(ins: Option[AbstractInsnNode]) = for (i <- ins) + throw new AssertionError(textify(i)) @Test def typeAccessible(): Unit = { @@ -176,15 +177,18 @@ class InlinerIllegalAccessTest extends ClearAfterClass { // PROTECTED - // protected accessed in same class, or protected static accessed in subclass(rgD). - // can be inlined to subclasses, and classes in the same package (gCl) - for ((m, declCls) <- Set((rcC, cCl), (rgC, cCl), (rgD, dCl)); c <- Set(cCl, dCl, eCl, fCl, gCl, hCl)) check(m, declCls, c, assertEmpty) + // protected static accessed in same class, or protected static accessed in subclass(rgD). + // can be inlined to sub- and superclasses, and classes in the same package (gCl) + for ((m, declCls) <- Set((rgC, cCl), (rgD, dCl)); c <- Set(cCl, dCl, eCl, fCl, gCl, hCl)) check(m, declCls, c, assertEmpty) // protected in non-subclass and different package for (m <- Set(rcC, rgC)) check(m, cCl, iCl, cOrDOwner) - // non-static protected accessed in subclass (rcD). can be inlined to related class, or classes in the same package - for (c <- Set(cCl, dCl, eCl, fCl, gCl)) check(rcD, dCl, c, assertEmpty) + // non-static protected accessed in subclass (rcD). + // can be inlined only if the destination class is related (sub- or superclass) or in the same package, + // AND if the receiver object is a subtype of the destination class + // TODO: we cannot check this yet, so the check flags the instruction as causing an IllegalAccess. https://github.com/scala-opt/scala/issues/13 + for ((m, declCls) <- Set((rcC, cCl), (rcD, dCl)); c <- Set(cCl, dCl, eCl, fCl, gCl)) check(m, declCls, c, cOrDOwner) // rcD cannot be inlined into non-related classes, if the declaration and destination are not in the same package for (c <- Set(hCl, iCl)) check(rcD, dCl, c, cOrDOwner) |