Don't do new captured type specific checks for old ones in the type checker

^KT-47143 Fixed
This commit is contained in:
Victor Petukhov
2021-06-08 14:22:39 +03:00
parent 02a56a3077
commit 1b82227308
11 changed files with 62 additions and 2 deletions
@@ -12944,6 +12944,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt");
}
@Test
@TestMetadata("dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt")
public void testDontCheckNewCapturedTypeSpecificChecksForOldOnes() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt");
}
@Test
@TestMetadata("expectedTypeMismatchWithInVariance.kt")
public void testExpectedTypeMismatchWithInVariance() throws Exception {
@@ -12944,6 +12944,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt");
}
@Test
@TestMetadata("dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt")
public void testDontCheckNewCapturedTypeSpecificChecksForOldOnes() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt");
}
@Test
@TestMetadata("expectedTypeMismatchWithInVariance.kt")
public void testExpectedTypeMismatchWithInVariance() throws Exception {
@@ -358,6 +358,8 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
return this.captureStatus
}
override fun CapturedTypeMarker.isOldCapturedType(): Boolean = false
override fun TypeConstructorMarker.isCapturedTypeConstructor(): Boolean {
return this is ConeCapturedTypeConstructor
}
@@ -157,6 +157,8 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
return this.captureStatus
}
override fun CapturedTypeMarker.isOldCapturedType(): Boolean = false
override fun CapturedTypeConstructorMarker.projection(): TypeArgumentMarker {
require(this is ConeCapturedTypeConstructor)
return this.projection
@@ -106,6 +106,8 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
override fun CapturedTypeMarker.captureStatus(): CaptureStatus =
(this as IrCapturedType).captureStatus
override fun CapturedTypeMarker.isOldCapturedType(): Boolean = false
override fun CapturedTypeConstructorMarker.projection(): TypeArgumentMarker =
(this as IrCapturedType.Constructor).argument
@@ -0,0 +1,14 @@
// FIR_IDENTICAL
// WITH_RUNTIME
// KT-47143
interface Container<PARAM: Any>
interface ContainerType<PARAM: Any, CONT: Container<PARAM>>
fun <R: Any> doGet(ep: ContainerType<*, *>): String = TODO()
@JvmName("name")
fun <R: Any, PARAM: Any, CONT: Container<PARAM>> doGet(ep: ContainerType<PARAM, CONT>): String = TODO()
fun main() {}
@@ -0,0 +1,17 @@
package
public fun </*0*/ R : kotlin.Any> doGet(/*0*/ ep: ContainerType<*, *>): kotlin.String
@kotlin.jvm.JvmName(name = "name") public fun </*0*/ R : kotlin.Any, /*1*/ PARAM : kotlin.Any, /*2*/ CONT : Container<PARAM>> doGet(/*0*/ ep: ContainerType<PARAM, CONT>): kotlin.String
public fun main(): kotlin.Unit
public interface Container</*0*/ PARAM : kotlin.Any> {
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
}
public interface ContainerType</*0*/ PARAM : kotlin.Any, /*1*/ CONT : Container<PARAM>> {
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
}
@@ -12950,6 +12950,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt");
}
@Test
@TestMetadata("dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt")
public void testDontCheckNewCapturedTypeSpecificChecksForOldOnes() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt");
}
@Test
@TestMetadata("expectedTypeMismatchWithInVariance.kt")
public void testExpectedTypeMismatchWithInVariance() throws Exception {
@@ -376,8 +376,9 @@ object AbstractTypeChecker {
): Boolean {
val simpleSubArgumentType = subArgumentType.asSimpleType()
if (simpleSubArgumentType !is CapturedTypeMarker || !simpleSubArgumentType.typeConstructor().projection().isStarProjection())
return false
if (simpleSubArgumentType !is CapturedTypeMarker || simpleSubArgumentType.isOldCapturedType()
|| !simpleSubArgumentType.typeConstructor().projection().isStarProjection()
) return false
// Only 'for subtyping' captured types are approximated before adding constraints (see ConstraintInjector.addNewIncorporatedConstraint)
// that can lead to adding problematic constraints like UPPER(Nothing) given by CapturedType(*) <: TypeVariable(A)
if (simpleSubArgumentType.captureStatus() != CaptureStatus.FOR_SUBTYPING) return false
@@ -285,6 +285,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker
fun KotlinTypeMarker.withNullability(nullable: Boolean): KotlinTypeMarker
fun CapturedTypeMarker.isOldCapturedType(): Boolean
fun CapturedTypeMarker.typeConstructor(): CapturedTypeConstructorMarker
fun CapturedTypeMarker.captureStatus(): CaptureStatus
fun CapturedTypeMarker.isProjectionNotNull(): Boolean
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructor
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
import org.jetbrains.kotlin.resolve.descriptorUtil.*
import org.jetbrains.kotlin.resolve.isInlineClass
@@ -462,6 +463,8 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
return this.captureStatus
}
override fun CapturedTypeMarker.isOldCapturedType(): Boolean = this is CapturedType
override fun KotlinTypeMarker.isNullableType(): Boolean {
require(this is KotlinType, this::errorMessage)
return TypeUtils.isNullableType(this)