generate correct cast for arguments of bridge methods (KT-2390)

This commit is contained in:
Dmitry Jemerov
2012-07-10 19:59:33 +02:00
parent f49232cdf3
commit 57c1b05684
3 changed files with 45 additions and 3 deletions
@@ -541,17 +541,18 @@ public class FunctionCodegen {
Type argType = argTypes[i];
iv.load(reg, argType);
if (argType.getSort() == Type.OBJECT) {
StackValue.onStack(JetTypeMapper.TYPE_OBJECT).put(method.getArgumentTypes()[i], iv);
StackValue.onStack(JetTypeMapper.TYPE_OBJECT).put(jvmSignature.getArgumentTypes()[i], iv);
}
else if (argType.getSort() == Type.ARRAY) {
StackValue.onStack(JetTypeMapper.ARRAY_GENERIC_TYPE).put(method.getArgumentTypes()[i], iv);
StackValue.onStack(JetTypeMapper.ARRAY_GENERIC_TYPE).put(jvmSignature.getArgumentTypes()[i], iv);
}
//noinspection AssignmentToForLoopParameter
reg += argType.getSize();
}
iv.invokevirtual(state.getInjector().getJetTypeMapper().mapType(((ClassDescriptor) owner.getContextDescriptor()).getDefaultType(), MapTypeMode.VALUE).getInternalName(), jvmSignature.getName(), jvmSignature.getDescriptor());
iv.invokevirtual(state.getInjector().getJetTypeMapper().mapType(((ClassDescriptor) owner.getContextDescriptor()).getDefaultType(), MapTypeMode.VALUE).getInternalName(),
jvmSignature.getName(), jvmSignature.getDescriptor());
if (JetTypeMapper.isPrimitive(jvmSignature.getReturnType()) && !JetTypeMapper.isPrimitive(overridden.getReturnType()))
StackValue.valueOf(iv, jvmSignature.getReturnType());
if (jvmSignature.getReturnType() == Type.VOID_TYPE)
@@ -0,0 +1,36 @@
import java.util.Collection
class JsonObject() {
}
class JsonArray() {
}
public trait Formatter<in IN: Any, out OUT: Any> {
public fun format(source: IN?): OUT
}
public trait MultiFormatter <in IN: Any, out OUT: Any> {
public fun format(source: Collection<IN>): OUT
}
public class Project() {
}
public trait JsonFormatter<in IN: Any>: Formatter<IN, JsonObject>, MultiFormatter<IN, JsonArray> {
public override fun format(source: Collection<IN>): JsonArray {
return JsonArray();
}
}
public class ProjectJsonFormatter(): JsonFormatter<Project> {
public override fun format(source: Project?): JsonObject {
return JsonObject()
}
}
fun box(): String {
val formatter = ProjectJsonFormatter()
return if (formatter.format(Project()) != null) "OK" else "fail"
}
@@ -456,4 +456,9 @@ public class ClassGenTest extends CodegenTestCase {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2384.kt");
}
public void testKt2390() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2390.kt");
}
}