Added canRemoveAfterTransformation method
This commit is contained in:
+7
-3
@@ -87,6 +87,13 @@ public class AnonymousObjectRegenerationInfo extends RegenerationInfo {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveAfterTransformation() {
|
||||
// Note: It is unsafe to remove anonymous class that is referenced by GETSTATIC within lambda
|
||||
// because it can be local function from outer scope
|
||||
return !isStaticOrigin;
|
||||
}
|
||||
|
||||
public Map<Integer, LambdaInfo> getLambdasToInline() {
|
||||
return lambdasToInline;
|
||||
}
|
||||
@@ -130,7 +137,4 @@ public class AnonymousObjectRegenerationInfo extends RegenerationInfo {
|
||||
return constructorDesc;
|
||||
}
|
||||
|
||||
public boolean isStaticOrigin() {
|
||||
return isStaticOrigin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,10 +196,8 @@ public class MethodInliner {
|
||||
result.addAllClassesToRemove(transformResult);
|
||||
result.addChangedType(oldClassName, newClassName);
|
||||
|
||||
if (inliningContext.isInliningLambda && !anonymousObjectGen.isStaticOrigin()) {
|
||||
if (inliningContext.isInliningLambda && anonymousObjectGen.canRemoveAfterTransformation()) {
|
||||
// this class is transformed and original not used so we should remove original one after inlining
|
||||
// Note: It is unsafe to remove anonymous class that is referenced by GETSTATIC within lambda
|
||||
// because it can be local function from outer scope
|
||||
result.addClassToRemove(oldClassName);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,21 @@ package org.jetbrains.kotlin.codegen.inline
|
||||
abstract class RegenerationInfo() {
|
||||
|
||||
abstract fun getOldClassName(): String
|
||||
|
||||
abstract fun getNewClassName(): String
|
||||
|
||||
abstract fun shouldRegenerate(sameModule: Boolean): Boolean
|
||||
|
||||
abstract fun canRemoveAfterTransformation(): Boolean
|
||||
|
||||
}
|
||||
|
||||
class WhenMappingRegenerationInfo(val oldName: String, val nameGenerator: NameGenerator) : RegenerationInfo() {
|
||||
|
||||
val newName by lazy {
|
||||
nameGenerator.genLambdaClassName() + oldName
|
||||
}
|
||||
|
||||
override fun shouldRegenerate(sameModule: Boolean): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
@@ -36,6 +43,10 @@ class WhenMappingRegenerationInfo(val oldName: String, val nameGenerator: NameGe
|
||||
}
|
||||
|
||||
override fun getNewClassName(): String {
|
||||
return nameGenerator.genLambdaClassName() + oldName
|
||||
return newName
|
||||
}
|
||||
|
||||
override fun canRemoveAfterTransformation(): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user