KT-2206 ClassFormatError on loading class with property inherited from trait
#KT-2206 fixed
This commit is contained in:
@@ -748,8 +748,26 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (jetClass.isTrait()) {
|
if (jetClass.isTrait()) {
|
||||||
int flags = ACC_PUBLIC; // TODO.
|
int flags = ACC_PUBLIC; // TODO.
|
||||||
|
|
||||||
Method function = typeMapper.mapSignature(fun.getName(), fun).getAsmMethod();
|
Method function;
|
||||||
Method functionOriginal = typeMapper.mapSignature(fun.getName(), fun.getOriginal()).getAsmMethod();
|
Method functionOriginal;
|
||||||
|
if (fun instanceof PropertyAccessorDescriptor) {
|
||||||
|
PropertyDescriptor property = ((PropertyAccessorDescriptor) fun).getCorrespondingProperty();
|
||||||
|
if (fun instanceof PropertyGetterDescriptor) {
|
||||||
|
function = typeMapper.mapGetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||||
|
functionOriginal = typeMapper.mapGetterSignature(property.getOriginal(), OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||||
|
}
|
||||||
|
else if (fun instanceof PropertySetterDescriptor) {
|
||||||
|
function = typeMapper.mapSetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||||
|
functionOriginal = typeMapper.mapSetterSignature(property.getOriginal(), OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new IllegalStateException("Accessor is neither getter, nor setter, what is it?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
function = typeMapper.mapSignature(fun.getName(), fun).getAsmMethod();
|
||||||
|
functionOriginal = typeMapper.mapSignature(fun.getName(), fun.getOriginal()).getAsmMethod();
|
||||||
|
}
|
||||||
|
|
||||||
final MethodVisitor mv = v.newMethod(myClass, flags, function.getName(), function.getDescriptor(), null, null);
|
final MethodVisitor mv = v.newMethod(myClass, flags, function.getName(), function.getDescriptor(), null, null);
|
||||||
AnnotationCodegen.forMethod(mv, state.getInjector().getJetTypeMapper()).genAnnotations(fun);
|
AnnotationCodegen.forMethod(mv, state.getInjector().getJetTypeMapper()).genAnnotations(fun);
|
||||||
@@ -758,12 +776,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
||||||
if (fun instanceof PropertyAccessorDescriptor) {
|
if (fun instanceof PropertyAccessorDescriptor) {
|
||||||
aw.writeFlags(JvmStdlibNames.JET_METHOD_FLAG_PROPERTY_BIT);
|
aw.writeFlags(JvmStdlibNames.JET_METHOD_FLAG_PROPERTY_BIT);
|
||||||
|
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||||
|
aw.writePropertyType(jvmSignature.getKotlinReturnType());
|
||||||
} else {
|
} else {
|
||||||
aw.writeFlags();
|
aw.writeFlags();
|
||||||
|
aw.writeNullableReturnType(fun.getReturnType().isNullable());
|
||||||
|
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||||
|
aw.writeReturnType(jvmSignature.getKotlinReturnType());
|
||||||
}
|
}
|
||||||
aw.writeNullableReturnType(fun.getReturnType().isNullable());
|
|
||||||
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
|
||||||
aw.writeReturnType(jvmSignature.getKotlinReturnType());
|
|
||||||
aw.visitEnd();
|
aw.visitEnd();
|
||||||
|
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
//KT-2206
|
||||||
|
trait A {
|
||||||
|
fun f():Int = 239
|
||||||
|
}
|
||||||
|
|
||||||
|
class B() : A
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
return if (B().f() == 239) "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
//KT-2206
|
||||||
|
|
||||||
|
trait A {
|
||||||
|
var a:Int
|
||||||
|
get() = 239
|
||||||
|
set(value) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B() : A
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
return if (B().a == 239) "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -48,4 +48,12 @@ public class TraitsTest extends CodegenTestCase {
|
|||||||
public void testStdlib () throws Exception {
|
public void testStdlib () throws Exception {
|
||||||
blackBoxFile("traits/stdlib.jet");
|
blackBoxFile("traits/stdlib.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInheritedFun() throws Exception {
|
||||||
|
blackBoxFile("traits/inheritedFun.jet");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testInheritedVar() throws Exception {
|
||||||
|
blackBoxFile("traits/inheritedVar.jet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user