[FE] Substitute erased type parameters as covariant

This commit is contained in:
Victor Petukhov
2022-04-25 18:59:52 +03:00
committed by teamcity
parent 4293b546ba
commit 54f0794ce3
8 changed files with 52 additions and 3 deletions
@@ -15499,6 +15499,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt");
}
@Test
@TestMetadata("recursiveTypeParameters.kt")
public void testRecursiveTypeParameters() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/recursiveTypeParameters.kt");
}
@Test
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
@@ -15499,6 +15499,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt");
}
@Test
@TestMetadata("recursiveTypeParameters.kt")
public void testRecursiveTypeParameters() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/recursiveTypeParameters.kt");
}
@Test
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
@@ -15499,6 +15499,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt");
}
@Test
@TestMetadata("recursiveTypeParameters.kt")
public void testRecursiveTypeParameters() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/recursiveTypeParameters.kt");
}
@Test
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator.commonSuperType
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.AbstractTypeRefiner
import org.jetbrains.kotlin.types.TypeCheckerState
@@ -389,7 +388,21 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
val typeParameterErasureMap = this.extractTypeParameters()
.map { (it as ConeTypeParameterLookupTag).typeParameterSymbol }
.eraseToUpperBoundsAssociated(session, intersectUpperBounds = true, eraseRecursively = true)
return ConeSubstitutorByMap(typeParameterErasureMap, session).safeSubstitute(this)
val substitutor by lazy { ConeSubstitutorByMap(typeParameterErasureMap, session) }
val typeWithErasedTypeParameters = if (argumentsCount() != 0) {
replaceArgumentsDeeply {
val type = it.getType()
val typeParameter =
(type.typeConstructor().getTypeParameterClassifier() as? ConeTypeParameterLookupTag)?.typeParameterSymbol
if (typeParameter != null) {
createTypeArgument(substitutor.safeSubstitute(type), TypeVariance.OUT)
} else it
}
} else if (typeConstructor().isTypeParameterTypeConstructor()) {
substitutor.safeSubstitute(this)
} else this
return typeWithErasedTypeParameters
}
override fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean {
@@ -0,0 +1,7 @@
// FIR_IDENTICAL
// WITH_STDLIB
// FULL_JDK
import java.util.*
fun <K : Enum<K>, V> enumMapOf(vararg pairs: Pair<K, V>): EnumMap<K, V> = EnumMap(mapOf(*pairs))
@@ -0,0 +1,3 @@
package
public fun </*0*/ K : kotlin.Enum<K>, /*1*/ V> enumMapOf(/*0*/ vararg pairs: kotlin.Pair<K, V> /*kotlin.Array<out kotlin.Pair<K, V>>*/): java.util.EnumMap<K, V>
@@ -15505,6 +15505,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt");
}
@Test
@TestMetadata("recursiveTypeParameters.kt")
public void testRecursiveTypeParameters() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/recursiveTypeParameters.kt");
}
@Test
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
@@ -716,7 +716,9 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
)
val typeParameters = this.extractTypeParameters()
.map { it as TypeParameterDescriptor }
.associateWith { TypeProjectionImpl(eraser.getErasedUpperBound(it, ErasureTypeAttributes(TypeUsage.COMMON))) }
.associateWith {
TypeProjectionImpl(Variance.OUT_VARIANCE, eraser.getErasedUpperBound(it, ErasureTypeAttributes(TypeUsage.COMMON)))
}
return TypeConstructorSubstitution.createByParametersMap(typeParameters).buildSubstitutor().safeSubstitute(this)
}