KT-2270 VerifyError when default value of constructor parameter is previous parameter
#KT-2270 Fixed
This commit is contained in:
@@ -444,6 +444,10 @@ public class FunctionCodegen {
|
||||
|
||||
FrameMap frameMap = owner.prepareFrame(state.getInjector().getJetTypeMapper());
|
||||
|
||||
if (kind instanceof OwnerKind.StaticDelegateKind) {
|
||||
frameMap.leaveTemp();
|
||||
}
|
||||
|
||||
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, jvmSignature.getReturnType(), owner, state);
|
||||
|
||||
int var = 0;
|
||||
@@ -452,15 +456,13 @@ public class FunctionCodegen {
|
||||
}
|
||||
|
||||
Type receiverType;
|
||||
if (receiverParameter.exists()) {
|
||||
if (hasReceiver) {
|
||||
receiverType = state.getInjector().getJetTypeMapper().mapType(receiverParameter.getType(), MapTypeMode.VALUE);
|
||||
var += receiverType.getSize();
|
||||
}
|
||||
else {
|
||||
receiverType = Type.DOUBLE_TYPE;
|
||||
}
|
||||
if (hasReceiver) {
|
||||
var += receiverType.getSize();
|
||||
}
|
||||
|
||||
Type[] argTypes = jvmSignature.getArgumentTypes();
|
||||
List<ValueParameterDescriptor> paramDescrs = functionDescriptor.getValueParameters();
|
||||
@@ -484,12 +486,15 @@ public class FunctionCodegen {
|
||||
|
||||
int extra = hasReceiver ? 1 : 0;
|
||||
|
||||
Type[] argumentTypes = jvmSignature.getArgumentTypes();
|
||||
for (int index = 0; index < paramDescrs.size(); index++) {
|
||||
ValueParameterDescriptor parameterDescriptor = paramDescrs.get(index);
|
||||
|
||||
Type t = argumentTypes[extra + index];
|
||||
Label endArg = null;
|
||||
Type t = argTypes[extra + index];
|
||||
|
||||
if (frameMap.getIndex(parameterDescriptor) < 0) {
|
||||
frameMap.enter(parameterDescriptor, t.getSize());
|
||||
}
|
||||
|
||||
if (parameterDescriptor.declaresDefaultValue()) {
|
||||
iv.load(maskIndex, Type.INT_TYPE);
|
||||
iv.iconst(1 << index);
|
||||
@@ -501,18 +506,14 @@ public class FunctionCodegen {
|
||||
assert jetParameter != null;
|
||||
codegen.gen(jetParameter.getDefaultValue(), t);
|
||||
|
||||
endArg = new Label();
|
||||
iv.goTo(endArg);
|
||||
int ind = frameMap.getIndex(parameterDescriptor);
|
||||
iv.store(ind, t);
|
||||
|
||||
iv.mark(loadArg);
|
||||
}
|
||||
|
||||
iv.load(var, t);
|
||||
var += t.getSize();
|
||||
|
||||
if (parameterDescriptor.declaresDefaultValue()) {
|
||||
iv.mark(endArg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isStatic) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
trait A {
|
||||
fun foo(x: Int, y: Int = x + 20, z: Int = y * 2) = z
|
||||
}
|
||||
|
||||
class B : A {}
|
||||
|
||||
fun box() = if (B().foo(1) == 42) "OK" else "Fail"
|
||||
@@ -0,0 +1,5 @@
|
||||
class A(val expected: Int) {
|
||||
fun foo(x: Int, y: Int = x + 20, z: Int = y * 2) = z == expected
|
||||
}
|
||||
|
||||
fun box() = if (A(42).foo(1)) "OK" else "Fail"
|
||||
@@ -0,0 +1,6 @@
|
||||
class A(
|
||||
val i : Int,
|
||||
val j : Int = i
|
||||
)
|
||||
|
||||
fun box() = if (A(1).j == 1) "OK" else "fail"
|
||||
@@ -68,6 +68,14 @@ public class FunctionGenTest extends CodegenTestCase {
|
||||
// System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testDefaultArgs6() {
|
||||
blackBoxFile("functions/defaultargs6.kt");
|
||||
}
|
||||
|
||||
public void testDefaultArgs7() {
|
||||
blackBoxFile("functions/defaultargs7.kt");
|
||||
}
|
||||
|
||||
public void testNoThisNoClosure() throws Exception {
|
||||
blackBoxFile("functions/nothisnoclosure.jet");
|
||||
// System.out.println(generateToText());
|
||||
@@ -121,7 +129,7 @@ public class FunctionGenTest extends CodegenTestCase {
|
||||
blackBoxFile("functions/invoke.kt");
|
||||
}
|
||||
|
||||
public void test2481() {
|
||||
public void testKt2481() {
|
||||
blackBoxFile("regressions/kt2481.kt");
|
||||
}
|
||||
|
||||
@@ -137,6 +145,10 @@ public class FunctionGenTest extends CodegenTestCase {
|
||||
blackBoxFile("regressions/kt2271.kt");
|
||||
}
|
||||
|
||||
public void testKt2270() {
|
||||
blackBoxFile("regressions/kt2270.kt");
|
||||
}
|
||||
|
||||
public static class WithJavaFunctionGenTest extends CodegenTestCase {
|
||||
private void blackBoxFileWithJava(@NotNull String ktFile) throws Exception {
|
||||
File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes");
|
||||
|
||||
Reference in New Issue
Block a user