summaryrefslogtreecommitdiff
path: root/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerIllegalAccessTest.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-05-27 17:29:03 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2015-05-28 11:42:40 +0200
commit7db3a58872593526c2cc175df633161f2ce9cccb (patch)
tree0f051049363fc48f3aba98eb676abe2362f2092d /test/junit/scala/tools/nsc/backend/jvm/opt/InlinerIllegalAccessTest.scala
parentbb302833c7bad6ff7591cdf6d10ec7ffdf683d6a (diff)
downloadscala-7db3a58872593526c2cc175df633161f2ce9cccb.tar.gz
scala-7db3a58872593526c2cc175df633161f2ce9cccb.tar.bz2
scala-7db3a58872593526c2cc175df633161f2ce9cccb.zip
Fix illegal inlining of instructions accessing protected members
There were two issues in the new inliner that would cause a VerifyError and an IllegalAccessError. First, an access to a public member of package protected class C can only be inlined if the destination class can access C. This is tested by t7582b. Second, an access to a protected member requires the receiver object to be a subtype of the class where the instruction is located. So when inlining such an access, we need to know the type of the receiver object - which we don't have. Therefore we don't inline in this case for now. This can be fixed once we have a type propagation analyis. https://github.com/scala-opt/scala/issues/13. This case is tested by t2106. Force kmpSliceSearch test to delambdafy:inline See discussion on https://github.com/scala/scala/pull/4505. The issue will go away when moving to indy-lambda.
Diffstat (limited to 'test/junit/scala/tools/nsc/backend/jvm/opt/InlinerIllegalAccessTest.scala')
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/InlinerIllegalAccessTest.scala16
1 files changed, 10 insertions, 6 deletions
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)