diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java index f80cd4b6a59..5f1ec072168 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1873,6 +1873,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/firProblems/SignatureClash.kt"); } + @TestMetadata("SyntheticSetterType.kt") + public void testSyntheticSetterType() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt"); + } + @TestMetadata("throwableStackTrace.kt") public void testThrowableStackTrace() throws Exception { runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt index 25e195c42c2..e81090204a9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt @@ -80,28 +80,22 @@ class FirSyntheticPropertiesScope( val parameter = setter.valueParameters.singleOrNull() ?: return if (setter.typeParameters.isNotEmpty() || setter.isStatic) return val parameterType = (parameter.returnTypeRef as? FirResolvedTypeRef)?.type ?: return - if (getter.symbol.dispatchReceiverClassOrNull() == setter.symbol.dispatchReceiverClassOrNull()) { - if (getterReturnType.withNullability(NOT_NULL) != parameterType.withNullability(NOT_NULL)) { - return - } - } else { - // TODO: at this moment it works for cases like - // class Base { - // void setSomething(Object value) {} - // } - // class Derived extends Base { - // String getSomething() { return ""; } - // } - // In FE 1.0, we should have also Object getSomething() in class Base for this to work - // I think details here are worth designing - if (!AbstractTypeChecker.isSubtypeOf( - session.typeContext, - getterReturnType.withNullability(NOT_NULL), - parameterType.withNullability(NOT_NULL) - ) - ) { - return - } + // TODO: at this moment it works for cases like + // class Base { + // void setSomething(Object value) {} + // } + // class Derived extends Base { + // String getSomething() { return ""; } + // } + // In FE 1.0, we should have also Object getSomething() in class Base for this to work + // I think details here are worth designing + if (!AbstractTypeChecker.isSubtypeOf( + session.typeContext, + getterReturnType.withNullability(NOT_NULL), + parameterType.withNullability(NOT_NULL) + ) + ) { + return } matchingSetter = setter }) diff --git a/compiler/testData/ir/irText/firProblems/SyntheticSetterType.fir.kt.txt b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.fir.kt.txt new file mode 100644 index 00000000000..617548322fa --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.fir.kt.txt @@ -0,0 +1,3 @@ +fun foo(descriptor: PropertyDescriptorImpl) { + descriptor.setOverriddenDescriptors(overriddenDescriptors = emptyList()) +} diff --git a/compiler/testData/ir/irText/firProblems/SyntheticSetterType.fir.txt b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.fir.txt new file mode 100644 index 00000000000..3d107bdafb2 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.fir.txt @@ -0,0 +1,8 @@ +FILE fqName: fileName:/SyntheticSetterType.kt + FUN name:foo visibility:public modality:FINAL <> (descriptor:.PropertyDescriptorImpl) returnType:kotlin.Unit + VALUE_PARAMETER name:descriptor index:0 type:.PropertyDescriptorImpl + BLOCK_BODY + CALL 'public open fun setOverriddenDescriptors (overriddenDescriptors: @[EnhancedNullability] kotlin.collections.Collection.CallableMemberDescriptor?>): kotlin.Unit declared in .PropertyDescriptorImpl' type=kotlin.Unit origin=EQ + $this: GET_VAR 'descriptor: .PropertyDescriptorImpl declared in .foo' type=.PropertyDescriptorImpl origin=null + overriddenDescriptors: CALL 'public final fun emptyList (): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List<.PropertyDescriptor?> origin=null + : .PropertyDescriptor? diff --git a/compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt new file mode 100644 index 00000000000..3a0d6011f78 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt @@ -0,0 +1,47 @@ +// WITH_RUNTIME +// FILE: PropertyDescriptorImpl.java + +import org.jetbrains.annotations.NotNull; +import java.util.*; + +public class PropertyDescriptorImpl implements PropertyDescriptor { + @Override + public void setOverriddenDescriptors(@NotNull Collection overriddenDescriptors) { + this.overriddenProperties = (Collection) overriddenDescriptors; + } + + @NotNull + @Override + public Collection getOverriddenDescriptors() { + return overriddenProperties != null ? overriddenProperties : Collections.emptyList(); + } +} + +// FILE: PropertyDescriptor.java + +import org.jetbrains.annotations.NotNull; +import java.util.*; + +public interface PropertyDescriptor extends CallableMemberDescriptor { + @NotNull + @Override + Collection getOverriddenDescriptors(); +} + +// FILE: CallableMemberDescriptor.java + +import org.jetbrains.annotations.NotNull; +import java.util.*; + +public interface CallableMemberDescriptor { + @NotNull + Collection getOverriddenDescriptors(); + + void setOverriddenDescriptors(@NotNull Collection overriddenDescriptors); +} + +// FILE: SyntheticSetterType.kt + +fun foo(descriptor: PropertyDescriptorImpl) { + descriptor.overriddenDescriptors = emptyList() +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt.txt b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt.txt new file mode 100644 index 00000000000..0fbad156101 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt.txt @@ -0,0 +1,3 @@ +fun foo(descriptor: PropertyDescriptorImpl) { + descriptor.setOverriddenDescriptors(overriddenDescriptors = emptyList<@FlexibleNullability PropertyDescriptor?>()) +} diff --git a/compiler/testData/ir/irText/firProblems/SyntheticSetterType.txt b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.txt new file mode 100644 index 00000000000..bcdd3eb5187 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/SyntheticSetterType.txt @@ -0,0 +1,8 @@ +FILE fqName: fileName:/SyntheticSetterType.kt + FUN name:foo visibility:public modality:FINAL <> (descriptor:.PropertyDescriptorImpl) returnType:kotlin.Unit + VALUE_PARAMETER name:descriptor index:0 type:.PropertyDescriptorImpl + BLOCK_BODY + CALL 'public open fun setOverriddenDescriptors (overriddenDescriptors: @[EnhancedNullability] kotlin.collections.MutableCollection.CallableMemberDescriptor?>): kotlin.Unit declared in .PropertyDescriptorImpl' type=kotlin.Unit origin=EQ + $this: GET_VAR 'descriptor: .PropertyDescriptorImpl declared in .foo' type=.PropertyDescriptorImpl origin=null + overriddenDescriptors: CALL 'public final fun emptyList (): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List<@[FlexibleNullability] .PropertyDescriptor?> origin=null + : @[FlexibleNullability] .PropertyDescriptor? diff --git a/compiler/tests-gen/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index e65b5d91e72..5223278165b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1872,6 +1872,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/firProblems/SignatureClash.kt"); } + @TestMetadata("SyntheticSetterType.kt") + public void testSyntheticSetterType() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt"); + } + @TestMetadata("throwableStackTrace.kt") public void testThrowableStackTrace() throws Exception { runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt");