diff --git a/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java b/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java index 06e887d98..2cc37fdfa 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java @@ -17,15 +17,22 @@ package org.teavm.classlib.impl; import java.util.ArrayList; import java.util.List; +import org.teavm.model.AccessLevel; +import org.teavm.model.BasicBlock; import org.teavm.model.ClassHolder; import org.teavm.model.ClassHolderTransformer; import org.teavm.model.ClassHolderTransformerContext; +import org.teavm.model.ElementModifier; import org.teavm.model.MethodHolder; +import org.teavm.model.Program; +import org.teavm.model.instructions.ExitInstruction; +import org.teavm.model.instructions.StringConstantInstruction; public class KotlinHacks implements ClassHolderTransformer { @Override public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { - if (cls.getName().equals("kotlin.jvm.internal.Lambda")) { + if (cls.getName().equals("kotlin.jvm.internal.Lambda") + || cls.getName().equals("kotlin.coroutines.jvm.internal.BaseContinuationImpl")) { List methodsToRemove = new ArrayList<>(); for (MethodHolder method : cls.getMethods()) { if (method.getName().equals("toString")) { @@ -35,6 +42,26 @@ public class KotlinHacks implements ClassHolderTransformer { for (MethodHolder method : methodsToRemove) { cls.removeMethod(method); } + } else if (cls.getName().equals("kotlin.jvm.internal.Reflection")) { + for (MethodHolder method : cls.getMethods()) { + if (method.getLevel() == AccessLevel.PUBLIC && method.hasModifier(ElementModifier.STATIC) + && method.getName().equals("renderLambdaToString") + && method.getResultType().isObject(String.class)) { + Program program = new Program(); + BasicBlock block = program.createBasicBlock(); + + StringConstantInstruction stringConstant = new StringConstantInstruction(); + stringConstant.setReceiver(program.createVariable()); + stringConstant.setConstant("lambda"); + block.add(stringConstant); + + ExitInstruction exit = new ExitInstruction(); + exit.setValueToReturn(stringConstant.getReceiver()); + block.add(exit); + + method.setProgram(program); + } + } } } }