IR: support buildSimpleType for IrCapturedType
To make it possible to change nullability of IrCapturedType and change its annotations, which is happening when determining overridability of functions via IR. #KT-63437 Fixed
This commit is contained in:
committed by
Space Team
parent
8379e48e33
commit
471f25abfc
+6
@@ -30564,6 +30564,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inheritanceWithWildcard.kt")
|
||||
public void testInheritanceWithWildcard() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/inheritanceWithWildcard.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaInterfaceFieldDirectAccess.kt")
|
||||
public void testJavaInterfaceFieldDirectAccess() throws Exception {
|
||||
|
||||
+6
@@ -30564,6 +30564,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inheritanceWithWildcard.kt")
|
||||
public void testInheritanceWithWildcard() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/inheritanceWithWildcard.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaInterfaceFieldDirectAccess.kt")
|
||||
public void testJavaInterfaceFieldDirectAccess() throws Exception {
|
||||
|
||||
+6
@@ -30169,6 +30169,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inheritanceWithWildcard.kt")
|
||||
public void testInheritanceWithWildcard() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/inheritanceWithWildcard.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaInterfaceFieldDirectAccess.kt")
|
||||
public void testJavaInterfaceFieldDirectAccess() throws Exception {
|
||||
|
||||
+6
@@ -30169,6 +30169,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inheritanceWithWildcard.kt")
|
||||
public void testInheritanceWithWildcard() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/inheritanceWithWildcard.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaInterfaceFieldDirectAccess.kt")
|
||||
public void testJavaInterfaceFieldDirectAccess() throws Exception {
|
||||
|
||||
+6
@@ -30169,6 +30169,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inheritanceWithWildcard.kt")
|
||||
public void testInheritanceWithWildcard() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/inheritanceWithWildcard.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaInterfaceFieldDirectAccess.kt")
|
||||
public void testJavaInterfaceFieldDirectAccess() throws Exception {
|
||||
|
||||
@@ -262,7 +262,9 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
argument.type
|
||||
} else null
|
||||
|
||||
IrCapturedType(status, lowerType, argument, typeParameters[index])
|
||||
IrCapturedType(
|
||||
status, lowerType, argument, typeParameters[index], SimpleTypeNullability.DEFINITELY_NOT_NULL, emptyList(), null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,10 @@ import org.jetbrains.kotlin.ir.symbols.FqNameEqualityChecker
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.model.CaptureStatus
|
||||
import org.jetbrains.kotlin.utils.compactIfPossible
|
||||
|
||||
abstract class IrAbstractSimpleType(kotlinType: KotlinType?) : IrSimpleType(kotlinType) {
|
||||
@@ -89,27 +91,60 @@ class IrSimpleTypeBuilder {
|
||||
var arguments: List<IrTypeArgument> = emptyList()
|
||||
var annotations: List<IrConstructorCall> = emptyList()
|
||||
var abbreviation: IrTypeAbbreviation? = null
|
||||
|
||||
var captureStatus: CaptureStatus? = null
|
||||
var capturedLowerType: IrType? = null
|
||||
var capturedTypeConstructor: IrCapturedType.Constructor? = null
|
||||
}
|
||||
|
||||
fun IrSimpleType.toBuilder() =
|
||||
fun IrSimpleType.toBuilder(): IrSimpleTypeBuilder =
|
||||
IrSimpleTypeBuilder().also { b ->
|
||||
b.kotlinType = originalKotlinType
|
||||
b.classifier = classifier
|
||||
if (this is IrCapturedType) {
|
||||
b.captureStatus = captureStatus
|
||||
b.capturedLowerType = lowerType
|
||||
b.capturedTypeConstructor = constructor
|
||||
} else {
|
||||
b.classifier = classifier
|
||||
}
|
||||
b.nullability = nullability
|
||||
b.arguments = arguments
|
||||
b.annotations = annotations
|
||||
b.abbreviation = abbreviation
|
||||
}
|
||||
|
||||
fun IrSimpleTypeBuilder.buildSimpleType() =
|
||||
IrSimpleTypeImpl(
|
||||
kotlinType,
|
||||
classifier ?: throw AssertionError("Classifier not provided"),
|
||||
nullability,
|
||||
arguments.compactIfPossible(),
|
||||
annotations.compactIfPossible(),
|
||||
abbreviation
|
||||
)
|
||||
fun IrSimpleTypeBuilder.buildSimpleType(): IrSimpleType =
|
||||
if (classifier == null) {
|
||||
check(captureStatus != null && capturedTypeConstructor != null) {
|
||||
"Neither classifier nor captured type constructor is provided"
|
||||
}
|
||||
check(arguments.isEmpty()) {
|
||||
"Arguments should be empty when creating a captured type: ${capturedTypeConstructor?.argument?.render()}"
|
||||
}
|
||||
IrCapturedType(
|
||||
captureStatus!!,
|
||||
capturedLowerType,
|
||||
capturedTypeConstructor!!.argument,
|
||||
capturedTypeConstructor!!.typeParameter,
|
||||
nullability,
|
||||
annotations.compactIfPossible(),
|
||||
abbreviation,
|
||||
).apply {
|
||||
constructor.initSuperTypes(capturedTypeConstructor!!.superTypes)
|
||||
}
|
||||
} else {
|
||||
check(captureStatus == null && capturedTypeConstructor == null) {
|
||||
"Both classifier and captured type constructor are provided"
|
||||
}
|
||||
IrSimpleTypeImpl(
|
||||
kotlinType,
|
||||
classifier ?: throw AssertionError("Classifier not provided"),
|
||||
nullability,
|
||||
arguments.compactIfPossible(),
|
||||
annotations.compactIfPossible(),
|
||||
abbreviation
|
||||
)
|
||||
}
|
||||
|
||||
fun IrSimpleTypeBuilder.buildTypeProjection(variance: Variance): IrTypeProjection =
|
||||
if (variance == Variance.INVARIANT)
|
||||
|
||||
@@ -71,7 +71,10 @@ class IrCapturedType(
|
||||
val captureStatus: CaptureStatus,
|
||||
val lowerType: IrType?,
|
||||
projection: IrTypeArgument,
|
||||
typeParameter: IrTypeParameter
|
||||
typeParameter: IrTypeParameter,
|
||||
override val nullability: SimpleTypeNullability,
|
||||
override val annotations: List<IrConstructorCall>,
|
||||
override val abbreviation: IrTypeAbbreviation?,
|
||||
) : IrSimpleType(null), CapturedTypeMarker {
|
||||
class Constructor(val argument: IrTypeArgument, val typeParameter: IrTypeParameter) : CapturedTypeConstructorMarker {
|
||||
var superTypes: List<IrType> = emptyList()
|
||||
@@ -85,10 +88,8 @@ class IrCapturedType(
|
||||
val constructor: Constructor = Constructor(projection, typeParameter)
|
||||
|
||||
override val classifier: IrClassifierSymbol get() = error("Captured Type does not have a classifier")
|
||||
|
||||
override val arguments: List<IrTypeArgument> get() = emptyList()
|
||||
override val abbreviation: IrTypeAbbreviation? get() = null
|
||||
override val nullability: SimpleTypeNullability get() = SimpleTypeNullability.DEFINITELY_NOT_NULL
|
||||
override val annotations: List<IrConstructorCall> get() = emptyList()
|
||||
|
||||
override fun equals(other: Any?): Boolean = this === other
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_LIGHT_ANALYSIS
|
||||
// FILE: A.java
|
||||
|
||||
interface A {
|
||||
X<? extends A> foo();
|
||||
|
||||
interface X<T extends A> {}
|
||||
}
|
||||
|
||||
interface B extends A {
|
||||
@Override
|
||||
Y<? extends B> foo();
|
||||
|
||||
interface Y<U extends B> extends X<U> {}
|
||||
}
|
||||
|
||||
class BImpl implements B {
|
||||
@Override
|
||||
public Y<? extends B> foo() { return null; }
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
private class D : A, BImpl()
|
||||
|
||||
fun box(): String =
|
||||
if (D().foo() == null) "OK" else "Fail"
|
||||
+6
@@ -28471,6 +28471,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inheritanceWithWildcard.kt")
|
||||
public void testInheritanceWithWildcard() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/inheritanceWithWildcard.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaOuterClassDependsOnInner.kt")
|
||||
public void testJavaOuterClassDependsOnInner() throws Exception {
|
||||
|
||||
+6
@@ -30169,6 +30169,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inheritanceWithWildcard.kt")
|
||||
public void testInheritanceWithWildcard() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/inheritanceWithWildcard.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaInterfaceFieldDirectAccess.kt")
|
||||
public void testJavaInterfaceFieldDirectAccess() throws Exception {
|
||||
|
||||
+6
@@ -30169,6 +30169,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inheritanceWithWildcard.kt")
|
||||
public void testInheritanceWithWildcard() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/inheritanceWithWildcard.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaInterfaceFieldDirectAccess.kt")
|
||||
public void testJavaInterfaceFieldDirectAccess() throws Exception {
|
||||
|
||||
+5
@@ -25530,6 +25530,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritanceWithWildcard.kt")
|
||||
public void testInheritanceWithWildcard() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/inheritanceWithWildcard.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaInterfaceFieldDirectAccess.kt")
|
||||
public void testJavaInterfaceFieldDirectAccess() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/javaInterfaceFieldDirectAccess.kt");
|
||||
|
||||
Reference in New Issue
Block a user