[NI] Remove capturing from supertypes during computation of CST
This commit is contained in:
@@ -141,7 +141,7 @@ fun ConeKotlinType.lowerBoundIfFlexible() = (this as? ConeFlexibleType)?.lowerBo
|
||||
class ConeCapturedTypeConstructor(
|
||||
val projection: ConeKotlinTypeProjection,
|
||||
var supertypes: List<ConeKotlinType>? = null
|
||||
) : TypeConstructorMarker
|
||||
) : CapturedTypeConstructorMarker
|
||||
|
||||
class ConeCapturedType(
|
||||
val captureStatus: CaptureStatus,
|
||||
|
||||
@@ -143,6 +143,21 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
return typeConstructor
|
||||
}
|
||||
|
||||
override fun CapturedTypeMarker.typeConstructor(): CapturedTypeConstructorMarker {
|
||||
require(this is ConeCapturedType)
|
||||
return this.constructor
|
||||
}
|
||||
|
||||
override fun CapturedTypeMarker.captureStatus(): CaptureStatus {
|
||||
require(this is ConeCapturedType)
|
||||
return this.captureStatus
|
||||
}
|
||||
|
||||
override fun CapturedTypeConstructorMarker.projection(): TypeArgumentMarker {
|
||||
require(this is ConeCapturedTypeConstructor)
|
||||
return this.projection
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.argumentsCount(): Int {
|
||||
require(this is ConeKotlinType)
|
||||
|
||||
|
||||
+5
@@ -10246,6 +10246,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/nestedLambdas.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonFixedVariableFromBothBranches.kt")
|
||||
public void testNonFixedVariableFromBothBranches() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableFromBothBranches.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonFixedVariableInsideFlexibleType.kt")
|
||||
public void testNonFixedVariableInsideFlexibleType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableInsideFlexibleType.kt");
|
||||
|
||||
@@ -72,6 +72,15 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
|
||||
override fun SimpleTypeMarker.typeConstructor() = (this as IrSimpleType).classifier
|
||||
|
||||
override fun CapturedTypeMarker.typeConstructor(): CapturedTypeConstructorMarker =
|
||||
error("Captured types should be used for IrTypes")
|
||||
|
||||
override fun CapturedTypeMarker.captureStatus(): CaptureStatus =
|
||||
error("Captured types should be used for IrTypes")
|
||||
|
||||
override fun CapturedTypeConstructorMarker.projection(): TypeArgumentMarker =
|
||||
error("Captured types should be used for IrTypes")
|
||||
|
||||
override fun KotlinTypeMarker.argumentsCount(): Int =
|
||||
when (this) {
|
||||
is IrSimpleType -> arguments.size
|
||||
|
||||
+20
-8
@@ -257,17 +257,22 @@ object NewCommonSuperTypeCalculator {
|
||||
val parameter = constructor.getParameter(index)
|
||||
var thereIsStar = false
|
||||
val typeProjections = correspondingSuperTypes.mapNotNull {
|
||||
it.getArgumentOrNull(index)?.let { typeArgument ->
|
||||
when {
|
||||
typeArgument.isStarProjection() -> {
|
||||
thereIsStar = true
|
||||
null
|
||||
}
|
||||
val typeArgumentFromSupertype = it.getArgumentOrNull(index) ?: return@mapNotNull null
|
||||
|
||||
typeArgument.getType().lowerBoundIfFlexible().isStubType() -> null
|
||||
// We have to uncapture types with status FOR_SUBTYPING because such captured types are creating during
|
||||
// `findCorrespondingSupertypes` call. Normally, we shouldn't create intermediate captured types here, it's needed only
|
||||
// to check subtyping. It'll be fixed but for a while we do this uncapturing here
|
||||
val typeArgument = uncaptureFromSubtyping(typeArgumentFromSupertype)
|
||||
|
||||
else -> typeArgument
|
||||
when {
|
||||
typeArgument.isStarProjection() -> {
|
||||
thereIsStar = true
|
||||
null
|
||||
}
|
||||
|
||||
typeArgument.getType().lowerBoundIfFlexible().isStubType() -> null
|
||||
|
||||
else -> typeArgument
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,6 +300,13 @@ object NewCommonSuperTypeCalculator {
|
||||
return createSimpleType(constructor, arguments, nullable = false)
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.uncaptureFromSubtyping(typeArgument: TypeArgumentMarker): TypeArgumentMarker {
|
||||
val capturedType = typeArgument.getType().asSimpleType()?.asCapturedType() ?: return typeArgument
|
||||
if (capturedType.captureStatus() != CaptureStatus.FOR_SUBTYPING) return typeArgument
|
||||
|
||||
return capturedType.typeConstructor().projection()
|
||||
}
|
||||
|
||||
// no star projections in arguments
|
||||
private fun TypeSystemCommonSuperTypesContext.calculateArgument(
|
||||
parameter: TypeParameterMarker,
|
||||
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||
|
||||
// FILE: JavaTest.java
|
||||
|
||||
public class JavaTest {
|
||||
public static Number[] createNumberArray() { return null; }
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun <K> select(x: K, y: K): K = x
|
||||
|
||||
fun <R> foo(f: () -> R): R = f()
|
||||
|
||||
fun test(n: Number) {
|
||||
val a = select(foo { JavaTest.createNumberArray() }, emptyArray())
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.Array<(kotlin.Number..kotlin.Number?)>..kotlin.Array<out (kotlin.Number..kotlin.Number?)>?)")!>a<!>
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ R> foo(/*0*/ f: () -> R): R
|
||||
public fun </*0*/ K> select(/*0*/ x: K, /*1*/ y: K): K
|
||||
public fun test(/*0*/ n: kotlin.Number): kotlin.Unit
|
||||
|
||||
public open class JavaTest {
|
||||
public constructor JavaTest()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public open fun createNumberArray(): kotlin.Array<(out) kotlin.Number!>!
|
||||
}
|
||||
@@ -10253,6 +10253,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/nestedLambdas.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonFixedVariableFromBothBranches.kt")
|
||||
public void testNonFixedVariableFromBothBranches() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableFromBothBranches.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonFixedVariableInsideFlexibleType.kt")
|
||||
public void testNonFixedVariableInsideFlexibleType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableInsideFlexibleType.kt");
|
||||
|
||||
Generated
+5
@@ -10248,6 +10248,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/nestedLambdas.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonFixedVariableFromBothBranches.kt")
|
||||
public void testNonFixedVariableFromBothBranches() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableFromBothBranches.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonFixedVariableInsideFlexibleType.kt")
|
||||
public void testNonFixedVariableInsideFlexibleType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableInsideFlexibleType.kt");
|
||||
|
||||
Reference in New Issue
Block a user