FIR synthetics: make setter subtype check more precise #KT-43347 Fixed
This commit is contained in:
+5
@@ -1873,6 +1873,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
|||||||
runTest("compiler/testData/ir/irText/firProblems/SignatureClash.kt");
|
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")
|
@TestMetadata("throwableStackTrace.kt")
|
||||||
public void testThrowableStackTrace() throws Exception {
|
public void testThrowableStackTrace() throws Exception {
|
||||||
runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt");
|
runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt");
|
||||||
|
|||||||
@@ -80,28 +80,22 @@ class FirSyntheticPropertiesScope(
|
|||||||
val parameter = setter.valueParameters.singleOrNull() ?: return
|
val parameter = setter.valueParameters.singleOrNull() ?: return
|
||||||
if (setter.typeParameters.isNotEmpty() || setter.isStatic) return
|
if (setter.typeParameters.isNotEmpty() || setter.isStatic) return
|
||||||
val parameterType = (parameter.returnTypeRef as? FirResolvedTypeRef)?.type ?: return
|
val parameterType = (parameter.returnTypeRef as? FirResolvedTypeRef)?.type ?: return
|
||||||
if (getter.symbol.dispatchReceiverClassOrNull() == setter.symbol.dispatchReceiverClassOrNull()) {
|
// TODO: at this moment it works for cases like
|
||||||
if (getterReturnType.withNullability(NOT_NULL) != parameterType.withNullability(NOT_NULL)) {
|
// class Base {
|
||||||
return
|
// void setSomething(Object value) {}
|
||||||
}
|
// }
|
||||||
} else {
|
// class Derived extends Base {
|
||||||
// TODO: at this moment it works for cases like
|
// String getSomething() { return ""; }
|
||||||
// class Base {
|
// }
|
||||||
// void setSomething(Object value) {}
|
// In FE 1.0, we should have also Object getSomething() in class Base for this to work
|
||||||
// }
|
// I think details here are worth designing
|
||||||
// class Derived extends Base {
|
if (!AbstractTypeChecker.isSubtypeOf(
|
||||||
// String getSomething() { return ""; }
|
session.typeContext,
|
||||||
// }
|
getterReturnType.withNullability(NOT_NULL),
|
||||||
// In FE 1.0, we should have also Object getSomething() in class Base for this to work
|
parameterType.withNullability(NOT_NULL)
|
||||||
// I think details here are worth designing
|
)
|
||||||
if (!AbstractTypeChecker.isSubtypeOf(
|
) {
|
||||||
session.typeContext,
|
return
|
||||||
getterReturnType.withNullability(NOT_NULL),
|
|
||||||
parameterType.withNullability(NOT_NULL)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
matchingSetter = setter
|
matchingSetter = setter
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(descriptor: PropertyDescriptorImpl) {
|
||||||
|
descriptor.setOverriddenDescriptors(overriddenDescriptors = emptyList<PropertyDescriptor?>())
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
FILE fqName:<root> fileName:/SyntheticSetterType.kt
|
||||||
|
FUN name:foo visibility:public modality:FINAL <> (descriptor:<root>.PropertyDescriptorImpl) returnType:kotlin.Unit
|
||||||
|
VALUE_PARAMETER name:descriptor index:0 type:<root>.PropertyDescriptorImpl
|
||||||
|
BLOCK_BODY
|
||||||
|
CALL 'public open fun setOverriddenDescriptors (overriddenDescriptors: @[EnhancedNullability] kotlin.collections.Collection<out <root>.CallableMemberDescriptor?>): kotlin.Unit declared in <root>.PropertyDescriptorImpl' type=kotlin.Unit origin=EQ
|
||||||
|
$this: GET_VAR 'descriptor: <root>.PropertyDescriptorImpl declared in <root>.foo' type=<root>.PropertyDescriptorImpl origin=null
|
||||||
|
overriddenDescriptors: CALL 'public final fun emptyList <T> (): kotlin.collections.List<T of kotlin.collections.emptyList> declared in kotlin.collections' type=kotlin.collections.List<<root>.PropertyDescriptor?> origin=null
|
||||||
|
<T>: <root>.PropertyDescriptor?
|
||||||
@@ -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<? extends CallableMemberDescriptor> overriddenDescriptors) {
|
||||||
|
this.overriddenProperties = (Collection<? extends PropertyDescriptor>) overriddenDescriptors;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<? extends PropertyDescriptor> getOverriddenDescriptors() {
|
||||||
|
return overriddenProperties != null ? overriddenProperties : Collections.<PropertyDescriptor>emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: PropertyDescriptor.java
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public interface PropertyDescriptor extends CallableMemberDescriptor {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
Collection<? extends PropertyDescriptor> getOverriddenDescriptors();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: CallableMemberDescriptor.java
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public interface CallableMemberDescriptor {
|
||||||
|
@NotNull
|
||||||
|
Collection<? extends CallableMemberDescriptor> getOverriddenDescriptors();
|
||||||
|
|
||||||
|
void setOverriddenDescriptors(@NotNull Collection<? extends CallableMemberDescriptor> overriddenDescriptors);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: SyntheticSetterType.kt
|
||||||
|
|
||||||
|
fun foo(descriptor: PropertyDescriptorImpl) {
|
||||||
|
descriptor.overriddenDescriptors = emptyList()
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(descriptor: PropertyDescriptorImpl) {
|
||||||
|
descriptor.setOverriddenDescriptors(overriddenDescriptors = emptyList<@FlexibleNullability PropertyDescriptor?>())
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
FILE fqName:<root> fileName:/SyntheticSetterType.kt
|
||||||
|
FUN name:foo visibility:public modality:FINAL <> (descriptor:<root>.PropertyDescriptorImpl) returnType:kotlin.Unit
|
||||||
|
VALUE_PARAMETER name:descriptor index:0 type:<root>.PropertyDescriptorImpl
|
||||||
|
BLOCK_BODY
|
||||||
|
CALL 'public open fun setOverriddenDescriptors (overriddenDescriptors: @[EnhancedNullability] kotlin.collections.MutableCollection<out @[FlexibleNullability] <root>.CallableMemberDescriptor?>): kotlin.Unit declared in <root>.PropertyDescriptorImpl' type=kotlin.Unit origin=EQ
|
||||||
|
$this: GET_VAR 'descriptor: <root>.PropertyDescriptorImpl declared in <root>.foo' type=<root>.PropertyDescriptorImpl origin=null
|
||||||
|
overriddenDescriptors: CALL 'public final fun emptyList <T> (): kotlin.collections.List<T of kotlin.collections.emptyList> declared in kotlin.collections' type=kotlin.collections.List<@[FlexibleNullability] <root>.PropertyDescriptor?> origin=null
|
||||||
|
<T>: @[FlexibleNullability] <root>.PropertyDescriptor?
|
||||||
@@ -1872,6 +1872,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
|||||||
runTest("compiler/testData/ir/irText/firProblems/SignatureClash.kt");
|
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")
|
@TestMetadata("throwableStackTrace.kt")
|
||||||
public void testThrowableStackTrace() throws Exception {
|
public void testThrowableStackTrace() throws Exception {
|
||||||
runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt");
|
runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user