Process non-aload0 outer access in constructor during inline

#KT-17972 Fixed
This commit is contained in:
Mikhael Bogdanov
2017-05-23 12:05:12 +02:00
committed by Michael Bogdanov
parent 5e265b3d17
commit 3f7bf8467a
13 changed files with 392 additions and 5 deletions
@@ -44,8 +44,15 @@ open class FieldRemapper(
else
foldFieldAccessChainIfNeeded(capturedFieldAccess, 1, node)
//TODO: seems that this method is redundant but it added from safety purposes before new milestone
open fun processNonAload0FieldAccessChains(isInlinedLambda: Boolean): Boolean = false
/**constructors could access outer not through
* ALOAD 0 //this
* GETFIELD this$0 //outer
* GETFIELD this$0 //outer of outer
* but directly through constructor parameter
* ALOAD X //outer
* GETFIELD this$0 //outer of outer
*/
open fun shouldProcessNonAload0FieldAccessChains(): Boolean = false
private fun foldFieldAccessChainIfNeeded(
capturedFieldAccess: List<AbstractInsnNode>,
@@ -602,7 +602,7 @@ class MethodInliner(
while (cur != null) {
if (cur is VarInsnNode && cur.opcode == Opcodes.ALOAD) {
val varIndex = cur.`var`
if (varIndex == 0 || nodeRemapper.processNonAload0FieldAccessChains(getLambdaIfExists(varIndex) != null)) {
if (varIndex == 0 || nodeRemapper.shouldProcessNonAload0FieldAccessChains()) {
val accessChain = getCapturedFieldAccessChain((cur as VarInsnNode?)!!)
val insnNode = nodeRemapper.foldFieldAccessChainIfNeeded(accessChain, node)
if (insnNode != null) {
@@ -46,8 +46,8 @@ class RegeneratedLambdaFieldRemapper(
return findFieldInSuper(fieldInsnNode)
}
override fun processNonAload0FieldAccessChains(isInlinedLambda: Boolean): Boolean {
return isInlinedLambda && isConstructor
override fun shouldProcessNonAload0FieldAccessChains(): Boolean {
return isConstructor
}
private fun findFieldInSuper(fieldInsnNode: FieldInsnNode): CapturedParamInfo? {