Fix for KT-9877: CompilationError: Cannot pop operand of empty stack

#KT-9877 Fixed
This commit is contained in:
Michael Bogdanov
2015-11-05 15:06:39 +03:00
parent 4d77181692
commit 0619ef47ac
8 changed files with 91 additions and 13 deletions
@@ -429,9 +429,11 @@ public class MethodInliner {
String desc = methodInsnNode.desc;
String name = methodInsnNode.name;
//TODO check closure
int paramLength = Type.getArgumentsAndReturnSizes(desc) >> 2;//non static
Type[] argTypes = Type.getArgumentTypes(desc);
int paramCount = argTypes.length + 1;//non static
int firstParameterIndex = frame.getStackSize() - paramCount;
if (isInvokeOnLambda(owner, name) /*&& methodInsnNode.owner.equals(INLINE_RUNTIME)*/) {
SourceValue sourceValue = frame.getStack(frame.getStackSize() - paramLength);
SourceValue sourceValue = frame.getStack(firstParameterIndex);
LambdaInfo lambdaInfo = null;
int varIndex = -1;
@@ -450,18 +452,19 @@ public class MethodInliner {
}
else if (isAnonymousConstructorCall(owner, name)) {
Map<Integer, LambdaInfo> lambdaMapping = new HashMap<Integer, LambdaInfo>();
int paramStart = frame.getStackSize() - paramLength;
for (int i = 0; i < paramLength; i++) {
SourceValue sourceValue = frame.getStack(paramStart + i);
int offset = 0;
for (int i = 0; i < paramCount; i++) {
SourceValue sourceValue = frame.getStack(firstParameterIndex + i);
if (sourceValue.insns.size() == 1) {
AbstractInsnNode insnNode = sourceValue.insns.iterator().next();
LambdaInfo lambdaInfo = getLambdaIfExists(insnNode);
if (lambdaInfo != null) {
lambdaMapping.put(i, lambdaInfo);
lambdaMapping.put(offset, lambdaInfo);
node.instructions.remove(insnNode);
}
}
offset += i == 0 ? 1 : argTypes[i - 1].getSize();
}
anonymousObjectGenerations.add(
@@ -0,0 +1,18 @@
import test.*
fun box(): String {
val loci = listOf("a", "b", "c")
var gene = "g1"
inlineCall {
val value = 10.0
loci.forEach {
var locusMap = 1.0
{
locusMap = value
gene = "OK"
}()
}
}
return gene
}
@@ -0,0 +1,10 @@
package test
fun <T> T.noInline(p: (T) -> Unit) {
p(this)
}
inline fun inlineCall(p: () -> Unit) {
p()
}
@@ -0,0 +1,17 @@
import test.*
fun box(): String {
var gene = "g1"
inlineCall {
val value = 10.0
inlineCall {
{
value
gene = "OK"
}()
}
}
return gene
}
@@ -0,0 +1,6 @@
package test
inline fun inlineCall(p: () -> Unit) {
p()
}
@@ -2712,24 +2712,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
@RunWith(JUnit3RunnerWithInners.class)
public static class Convention extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInConvention() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/defaultArguments/convention"), Pattern.compile("^(.+)\\.kt$"), true);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/defaultArguments/convention"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("incWithDefaultInGetter.kt")
public void testIncWithDefaultInGetter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/incWithDefaultInGetter.kt");
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/incWithDefaultInGetter.kt");
doTest(fileName);
}
@TestMetadata("kt9140.kt")
public void testKt9140() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/kt9140.kt");
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/kt9140.kt");
doTest(fileName);
}
@TestMetadata("plusAssignWithDefaultInGetter.kt")
public void testPlusAssignWithDefaultInGetter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/plusAssignWithDefaultInGetter.kt");
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/plusAssignWithDefaultInGetter.kt");
doTest(fileName);
}
}
@@ -6427,18 +6427,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
@RunWith(JUnit3RunnerWithInners.class)
public static class Private extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInPrivate() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/private"), Pattern.compile("^(.+)\\.kt$"), true);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/private"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("arrayConvention.kt")
public void testArrayConvention() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/private/arrayConvention.kt");
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/private/arrayConvention.kt");
doTest(fileName);
}
@TestMetadata("kt9855.kt")
public void testKt9855() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/private/kt9855.kt");
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/private/kt9855.kt");
doTest(fileName);
}
}
@@ -138,6 +138,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9064v2.1.kt");
doTestMultiFileWithInlineCheck(fileName);
}
@TestMetadata("kt9877.1.kt")
public void testKt9877() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9877.1.kt");
doTestMultiFileWithInlineCheck(fileName);
}
@TestMetadata("kt9877_2.1.kt")
public void testKt9877_2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.1.kt");
doTestMultiFileWithInlineCheck(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/argumentOrder")
@@ -138,6 +138,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9064v2.1.kt");
doBoxTestWithInlineCheck(fileName);
}
@TestMetadata("kt9877.1.kt")
public void testKt9877() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9877.1.kt");
doBoxTestWithInlineCheck(fileName);
}
@TestMetadata("kt9877_2.1.kt")
public void testKt9877_2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.1.kt");
doBoxTestWithInlineCheck(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/argumentOrder")