[FE] Substitute erased type parameters as covariant
This commit is contained in:
committed by
teamcity
parent
4293b546ba
commit
54f0794ce3
+6
@@ -15499,6 +15499,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt");
|
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
|
@Test
|
||||||
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
|
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
|
||||||
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
|
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
|
||||||
|
|||||||
+6
@@ -15499,6 +15499,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt");
|
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
|
@Test
|
||||||
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
|
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
|
||||||
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
|
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
|
||||||
|
|||||||
+6
@@ -15499,6 +15499,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt");
|
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
|
@Test
|
||||||
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
|
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
|
||||||
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
|
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.ConeClassLikeTypeImpl
|
||||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||||
import org.jetbrains.kotlin.name.StandardClassIds
|
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.AbstractTypeChecker
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeRefiner
|
import org.jetbrains.kotlin.types.AbstractTypeRefiner
|
||||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||||
@@ -389,7 +388,21 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
val typeParameterErasureMap = this.extractTypeParameters()
|
val typeParameterErasureMap = this.extractTypeParameters()
|
||||||
.map { (it as ConeTypeParameterLookupTag).typeParameterSymbol }
|
.map { (it as ConeTypeParameterLookupTag).typeParameterSymbol }
|
||||||
.eraseToUpperBoundsAssociated(session, intersectUpperBounds = true, eraseRecursively = true)
|
.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 {
|
override fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean {
|
||||||
|
|||||||
Vendored
+7
@@ -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))
|
||||||
Vendored
+3
@@ -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>
|
||||||
Generated
+6
@@ -15505,6 +15505,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt");
|
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
|
@Test
|
||||||
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
|
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
|
||||||
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
|
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
|
||||||
|
|||||||
@@ -716,7 +716,9 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
|||||||
)
|
)
|
||||||
val typeParameters = this.extractTypeParameters()
|
val typeParameters = this.extractTypeParameters()
|
||||||
.map { it as TypeParameterDescriptor }
|
.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)
|
return TypeConstructorSubstitution.createByParametersMap(typeParameters).buildSubstitutor().safeSubstitute(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user