Fix mapGetterSignature/mapSetterSignature
In case of TRAIT_IMPL the incorrect this was written. Reuse the code from the common mapSignature #KT-3413 Fixed
This commit is contained in:
@@ -729,24 +729,8 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter);
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
@SuppressWarnings("ConstantConditions") ClassDescriptor containingDeclaration = (ClassDescriptor) parentDescriptor;
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
mapType(containingDeclaration.getDefaultType(), signatureWriter, JetTypeMapperMode.IMPL);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
else {
|
||||
if (descriptor instanceof AccessorForPropertyDescriptor) {
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
mapType(((ClassifierDescriptor) descriptor.getContainingDeclaration()).getDefaultType(), signatureWriter,
|
||||
JetTypeMapperMode.VALUE);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
writeThisIfNeeded(descriptor, kind, signatureWriter);
|
||||
writeReceiverIfNeeded(descriptor.getReceiverParameter(), signatureWriter);
|
||||
|
||||
signatureWriter.writeParametersEnd();
|
||||
|
||||
signatureWriter.writeReturnType();
|
||||
@@ -767,34 +751,15 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
|
||||
writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter);
|
||||
|
||||
JetType outType = descriptor.getType();
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
|
||||
String name = PropertyCodegen.setterName(descriptor.getName());
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) descriptor.getContainingDeclaration();
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
mapType(containingDeclaration.getDefaultType(), signatureWriter, JetTypeMapperMode.VALUE);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
else {
|
||||
if (descriptor instanceof AccessorForPropertyDescriptor) {
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
mapType(((ClassifierDescriptor) descriptor.getContainingDeclaration()).getDefaultType(), signatureWriter,
|
||||
JetTypeMapperMode.VALUE);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
writeThisIfNeeded(descriptor, kind, signatureWriter);
|
||||
writeReceiverIfNeeded(descriptor.getReceiverParameter(), signatureWriter);
|
||||
|
||||
writeParameter(signatureWriter, outType);
|
||||
|
||||
writeParameter(signatureWriter, descriptor.getType());
|
||||
signatureWriter.writeParametersEnd();
|
||||
|
||||
signatureWriter.writeVoidReturn();
|
||||
|
||||
String name = PropertyCodegen.setterName(descriptor.getName());
|
||||
JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name);
|
||||
return new JvmPropertyAccessorSignature(jvmMethodSignature,
|
||||
jvmMethodSignature.getKotlinParameterType(jvmMethodSignature.getParameterCount() - 1));
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
abstract class Base<T> {
|
||||
abstract var s: T
|
||||
}
|
||||
|
||||
trait Trait<T> : Base<T> {
|
||||
var value : T
|
||||
get() = s
|
||||
set(value) { s = value }
|
||||
}
|
||||
|
||||
class Derived : Trait<String>, Base<String>() {
|
||||
override var s = "Fail"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val d = Derived()
|
||||
d.value = "OK"
|
||||
return d.value
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
open class Base {
|
||||
var s = "Fail"
|
||||
}
|
||||
|
||||
trait Trait : Base {
|
||||
var value : String
|
||||
get() = s
|
||||
set(value) { s = value }
|
||||
}
|
||||
|
||||
class Derived : Trait, Base()
|
||||
|
||||
fun box(): String {
|
||||
val d = Derived()
|
||||
d.value = "OK"
|
||||
return d.value
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
open class Base
|
||||
|
||||
trait Trait : Base {
|
||||
private val value : String
|
||||
get() = "OK"
|
||||
|
||||
fun toString() = object {
|
||||
fun foo() = value
|
||||
}.foo()
|
||||
}
|
||||
|
||||
class Derived : Trait, Base()
|
||||
|
||||
fun box() = "${Derived()}"
|
||||
@@ -3275,6 +3275,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest("compiler/testData/codegen/box/traits/withRequired.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withRequiredGenericProperty.kt")
|
||||
public void testWithRequiredGenericProperty() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/traits/withRequiredGenericProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withRequiredProperty.kt")
|
||||
public void testWithRequiredProperty() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/traits/withRequiredProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withRequiredPropertyViaBridge.kt")
|
||||
public void testWithRequiredPropertyViaBridge() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/traits/withRequiredPropertyViaBridge.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withRequiredSuper.kt")
|
||||
public void testWithRequiredSuper() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/traits/withRequiredSuper.kt");
|
||||
|
||||
Reference in New Issue
Block a user