From b64cb6737096ad354096d938ca77cb71e653c6c1 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 28 Feb 2023 09:40:19 +0100 Subject: [PATCH] K2: support ForbidInferringTypeVariablesIntoEmptyIntersection on/off --- .../diagnostics/KtFirDataClassConverters.kt | 16 +++++++- .../api/fir/diagnostics/KtFirDiagnostics.kt | 12 +++++- .../fir/diagnostics/KtFirDiagnosticsImpl.kt | 13 ++++++- .../diagnostics/FirDiagnosticsList.kt | 4 +- .../fir/analysis/diagnostics/FirErrors.kt | 3 +- .../coneDiagnosticToFirDiagnostic.kt | 26 +++++++++---- .../fir/resolve/calls/ResolutionStages.kt | 5 ++- .../fir/resolve/calls/ResolutionDiagnostic.kt | 3 +- .../coercionToUnit/afterBareReturn.fir.kt | 2 +- .../coercionToUnitWithNothingType.fir.kt | 2 +- ...nVariableHasComplexIntersectionType.fir.kt | 37 ------------------- ...eWhenVariableHasComplexIntersectionType.kt | 1 + .../emptyIntersectionTypes/kt45461.fir.kt | 11 ------ .../emptyIntersectionTypes/kt45461.kt | 1 + .../emptyIntersectionTypes/kt45461_12.fir.kt | 13 ------- .../emptyIntersectionTypes/kt45461_12.kt | 1 + .../emptyIntersectionTypes/kt45461_2.fir.kt | 11 ------ .../emptyIntersectionTypes/kt45461_2.kt | 1 + .../emptyIntersectionTypes/kt45461_25.fir.kt | 2 +- .../emptyIntersectionTypes/kt45461_5.fir.kt | 11 ------ .../emptyIntersectionTypes/kt45461_5.kt | 1 + .../emptyIntersectionTypes/kt48765.fir.kt | 17 --------- .../emptyIntersectionTypes/kt48765.kt | 1 + .../emptyIntersectionTypes/kt48935_3.fir.kt | 11 ------ .../emptyIntersectionTypes/kt48935_3.kt | 1 + .../emptyIntersectionTypes/kt48935_4.fir.kt | 11 ------ .../emptyIntersectionTypes/kt48935_4.kt | 1 + .../emptyIntersectionTypes/kt48987.fir.kt | 2 +- .../emptyIntersectionTypes/kt49661.fir.kt | 11 ------ .../emptyIntersectionTypes/kt49661.kt | 1 + .../nullableEmptyIntersection.fir.kt | 7 ---- .../nullableEmptyIntersection.kt | 1 + ...tFromCovariantAndContravariantTypes.fir.kt | 20 ---------- ...electFromCovariantAndContravariantTypes.kt | 1 + ...IntersectUpperBoundWithExpectedType.fir.kt | 2 +- .../tests/typeParameters/kt46186.fir.kt | 4 +- .../tests/when/TypeParameterError.fir.kt | 25 ------------- .../tests/when/TypeParameterError.kt | 1 + .../tests/when/TypeParameterWarning.fir.kt | 25 ------------- .../tests/when/TypeParameterWarning.kt | 1 + .../testsWithStdLib/greater.fir.kt | 12 ------ .../diagnostics/testsWithStdLib/greater.kt | 1 + .../exactAnnotation.fir.kt | 2 +- 43 files changed, 86 insertions(+), 248 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/when/TypeParameterError.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/when/TypeParameterWarning.fir.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt index f65b04c17b9..bc8a07c0585 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -2224,8 +2224,20 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } - add(FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION) { firDiagnostic -> - InferredTypeVariableIntoEmptyIntersectionImpl( + add(FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION.errorFactory) { firDiagnostic -> + InferredTypeVariableIntoEmptyIntersectionErrorImpl( + firDiagnostic.a, + firDiagnostic.b.map { coneKotlinType -> + firSymbolBuilder.typeBuilder.buildKtType(coneKotlinType) + }, + firDiagnostic.c, + firDiagnostic.d, + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION.warningFactory) { firDiagnostic -> + InferredTypeVariableIntoEmptyIntersectionWarningImpl( firDiagnostic.a, firDiagnostic.b.map { coneKotlinType -> firSymbolBuilder.typeBuilder.buildKtType(coneKotlinType) diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt index f9021b5c648..724c7a2225f 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt @@ -1579,8 +1579,16 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { abstract val kotlinClass: FqName } - abstract class InferredTypeVariableIntoEmptyIntersection : KtFirDiagnostic() { - override val diagnosticClass get() = InferredTypeVariableIntoEmptyIntersection::class + abstract class InferredTypeVariableIntoEmptyIntersectionError : KtFirDiagnostic() { + override val diagnosticClass get() = InferredTypeVariableIntoEmptyIntersectionError::class + abstract val typeVariableDescription: String + abstract val incompatibleTypes: List + abstract val description: String + abstract val causingTypes: String + } + + abstract class InferredTypeVariableIntoEmptyIntersectionWarning : KtFirDiagnostic() { + override val diagnosticClass get() = InferredTypeVariableIntoEmptyIntersectionWarning::class abstract val typeVariableDescription: String abstract val incompatibleTypes: List abstract val description: String diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index a6350fc1117..c014aa37aee 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -1899,14 +1899,23 @@ internal class PlatformClassMappedToKotlinImpl( override val token: KtLifetimeToken, ) : KtFirDiagnostic.PlatformClassMappedToKotlin(), KtAbstractFirDiagnostic -internal class InferredTypeVariableIntoEmptyIntersectionImpl( +internal class InferredTypeVariableIntoEmptyIntersectionErrorImpl( override val typeVariableDescription: String, override val incompatibleTypes: List, override val description: String, override val causingTypes: String, override val firDiagnostic: KtPsiDiagnostic, override val token: KtLifetimeToken, -) : KtFirDiagnostic.InferredTypeVariableIntoEmptyIntersection(), KtAbstractFirDiagnostic +) : KtFirDiagnostic.InferredTypeVariableIntoEmptyIntersectionError(), KtAbstractFirDiagnostic + +internal class InferredTypeVariableIntoEmptyIntersectionWarningImpl( + override val typeVariableDescription: String, + override val incompatibleTypes: List, + override val description: String, + override val causingTypes: String, + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.InferredTypeVariableIntoEmptyIntersectionWarning(), KtAbstractFirDiagnostic internal class InferredTypeVariableIntoPossibleEmptyIntersectionImpl( override val typeVariableDescription: String, diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index 563353d98af..052abc5b87e 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -737,7 +737,9 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { parameter("kotlinClass") } - val INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION by error { + val INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION by deprecationError( + LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection + ) { parameter("typeVariableDescription") parameter>("incompatibleTypes") parameter("description") diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 3011aa389c0..69972d4d060 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature.ForbidExposingTypesInPrimaryConstructorProperties +import org.jetbrains.kotlin.config.LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection import org.jetbrains.kotlin.config.LanguageFeature.ForbidUsingExtensionPropertyTypeParameterInDelegate import org.jetbrains.kotlin.config.LanguageFeature.ModifierNonBuiltinSuspendFunError import org.jetbrains.kotlin.config.LanguageFeature.ProhibitAssigningSingleElementsToVarargsInNamedForm @@ -433,7 +434,7 @@ object FirErrors { val SMARTCAST_IMPOSSIBLE by error4() val REDUNDANT_NULLABLE by warning0(SourceElementPositioningStrategies.REDUNDANT_NULLABLE) val PLATFORM_CLASS_MAPPED_TO_KOTLIN by warning1(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED) - val INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION by error4, String, String>() + val INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION by deprecationError4, String, String>(ForbidInferringTypeVariablesIntoEmptyIntersection) val INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION by warning4, String, String>() val INCORRECT_LEFT_COMPONENT_OF_INTERSECTION by error0() val INCORRECT_RIGHT_COMPONENT_OF_INTERSECTION by error0() diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 0b69cdef3f5..90ca06a0b8d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -292,8 +292,13 @@ private fun mapInapplicableCandidateError( ) } - is InferredEmptyIntersectionDiagnostic -> reportInferredIntoEmptyIntersectionError( - source, rootCause.typeVariable, rootCause.incompatibleTypes, rootCause.causingTypes, rootCause.kind + is InferredEmptyIntersectionDiagnostic -> reportInferredIntoEmptyIntersection( + source, + rootCause.typeVariable, + rootCause.incompatibleTypes, + rootCause.causingTypes, + rootCause.kind, + isError = rootCause.isError ) else -> genericDiagnostic @@ -434,12 +439,13 @@ private fun ConstraintSystemError.toDiagnostic( is InferredEmptyIntersection -> { @Suppress("UNCHECKED_CAST") - reportInferredIntoEmptyIntersectionError( + reportInferredIntoEmptyIntersection( source, typeVariable as ConeTypeVariable, incompatibleTypes as Collection, causingTypes as Collection, - kind + kind, + this is InferredEmptyIntersectionError, ) } @@ -454,20 +460,24 @@ private fun ConstraintSystemError.toDiagnostic( } } -private fun reportInferredIntoEmptyIntersectionError( +private fun reportInferredIntoEmptyIntersection( source: KtSourceElement, typeVariable: ConeTypeVariable, incompatibleTypes: Collection, causingTypes: Collection, - kind: EmptyIntersectionTypeKind + kind: EmptyIntersectionTypeKind, + isError: Boolean ): KtDiagnostic? { val typeVariableText = (typeVariable.typeConstructor.originalTypeParameter as? ConeTypeParameterLookupTag)?.name?.asString() ?: typeVariable.toString() val causingTypesText = if (incompatibleTypes == causingTypes) "" else ": ${causingTypes.joinToString()}" val factory = - if (kind.isDefinitelyEmpty) FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION - else FirErrors.INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION + when { + !kind.isDefinitelyEmpty -> FirErrors.INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION + isError -> FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION.errorFactory + else -> FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION.warningFactory + } return factory.createOn(source, typeVariableText, incompatibleTypes, kind.description, causingTypesText) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index abfff0632b5..3f29ca55bfc 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -597,7 +597,10 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionStage() { upperTypes as List, emptyIntersectionTypeInfo.casingTypes.toList() as List, variableWithConstraints.typeVariable as ConeTypeVariable, - emptyIntersectionTypeInfo.kind + emptyIntersectionTypeInfo.kind, + isError = context.session.languageVersionSettings.supportsFeature( + LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection + ) ) ) } diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt index 1dc2b010a38..47ede463b10 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt @@ -33,7 +33,8 @@ class InferredEmptyIntersectionDiagnostic( val incompatibleTypes: Collection, val causingTypes: Collection, val typeVariable: ConeTypeVariable, - val kind: EmptyIntersectionTypeKind + val kind: EmptyIntersectionTypeKind, + val isError: Boolean ) : ResolutionDiagnostic(INAPPLICABLE) class TooManyArguments( diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt index 2b90328b8ab..1ceca4d4ca9 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt @@ -27,7 +27,7 @@ fun test3() = run { incompatibleI() // ? either uninferred T or error (Unit run { +fun test4() = run { if (p) return@run incompatibleC() // ? either uninferred T or error (Unit , iUnit: Inv) { if (iUnit is String) { launch { - run(A.flexible(iUnit)) { 42 } + run(A.flexible(iUnit)) { 42 } } } } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.fir.kt deleted file mode 100644 index 5f685277f58..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.fir.kt +++ /dev/null @@ -1,37 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION - -abstract class Foo - -abstract class Bar : Foo(), Comparable> - -object Scope { - fun , S : T> greater(x: Bar, other: Foo) {} - - object Nested { - fun , S : T> greater(x: Bar, t: T) {} - - fun test(b: Bar) { - greater(b, b) - } - } -} - -object OnlyOne { - fun , S : T> greater(x: Bar, t: T) {} - - fun test(b: Bar) { - greater(b, b) - } -} - -object GoodOldCandidate { - fun , S : T> greater(x: Bar, t: T) {} - - object Nested { - fun , S : T> greater(x: Bar, other: Foo) {} - - fun test(b: Bar) { - greater(b, b) - } - } -} diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt index c266cfd2735..ef60a52fcbb 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION abstract class Foo diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.fir.kt deleted file mode 100644 index 3986ceffcc1..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -// RENDER_DIAGNOSTICS_FULL_TEXT -class Foo - -class Bar { - fun takeFoo(foo: Foo) {} -} - -fun main() { - val foo = Foo() - Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt index e40831994e8..823b6c8e4af 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // RENDER_DIAGNOSTICS_FULL_TEXT class Foo diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.fir.kt deleted file mode 100644 index 5ab681631cd..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.fir.kt +++ /dev/null @@ -1,13 +0,0 @@ -// RENDER_DIAGNOSTICS_FULL_TEXT -class Foo - -class Bar { - fun takeFoo(foo: Foo) {} -} - -interface A - -fun main() where N: A, N: Number { - val foo = Foo() - Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 -} diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.kt index 7dad9ad84c1..d7731f0126f 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // RENDER_DIAGNOSTICS_FULL_TEXT class Foo diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.fir.kt deleted file mode 100644 index c14087db519..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -// RENDER_DIAGNOSTICS_FULL_TEXT -class Foo - -class Bar { - fun takeFoo(foo: Foo) {} -} - -fun Int> main() { - val foo = Foo() - Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.kt index 2781cfc959b..038526470b0 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // RENDER_DIAGNOSTICS_FULL_TEXT class Foo diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_25.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_25.fir.kt index ec10f168ad0..e423e760874 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_25.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_25.fir.kt @@ -8,5 +8,5 @@ class Bar { fun Int> main() { val foo = Foo() - val x: Float = Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + val x: Float = Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.fir.kt deleted file mode 100644 index b48314f6e46..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -// RENDER_DIAGNOSTICS_FULL_TEXT -class Foo - -class Bar { - fun takeFoo(foo: Foo) {} -} - -fun main() { - val foo = Foo() - Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 -} diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.kt index cc208e86568..c0f0085f991 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // RENDER_DIAGNOSTICS_FULL_TEXT class Foo diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.fir.kt deleted file mode 100644 index fc93724b074..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.fir.kt +++ /dev/null @@ -1,17 +0,0 @@ -// RENDER_DIAGNOSTICS_FULL_TEXT -open class A {} -class B { - fun > foo(x1: T2, x2: T1) {} -} -class C(val x: T, val y: T2) { - fun test() { - B().foo(x, foo()) - } -} -open class D: A() -fun String> foo(): T { - return "" as T // this cast is safe because String is final. -} -fun main() { - C(D(), 10.5).test() -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.kt index 05acaf924fd..e32a9babf44 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // RENDER_DIAGNOSTICS_FULL_TEXT open class A {} class B { diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.fir.kt deleted file mode 100644 index 6d46a76d6e1..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -open class Base -open class DoesNotImplementBase - -fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { - -} - -fun main() { - val func: (DoesNotImplementBase) -> Unit = { } - exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.kt index 4359b1fbd96..2497f141e37 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL open class Base open class DoesNotImplementBase diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.fir.kt deleted file mode 100644 index 86c6aea199c..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -open class Base -class DoesNotImplementBase - -fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { - -} - -fun main() { - val func: (DoesNotImplementBase) -> Unit = { } - exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.kt index bac2fc1c8c6..29f98f40125 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL open class Base class DoesNotImplementBase diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.fir.kt index 9a94ec31203..67db13724a2 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.fir.kt @@ -5,7 +5,7 @@ fun box(): String { return try { val range1 = 0..1 range1 as List - range1.joinToString { "" } + range1.joinToString { "" } } catch (e: java.lang.ClassCastException) { "OK" } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.fir.kt deleted file mode 100644 index 696829e1fbd..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -// RENDER_DIAGNOSTICS_FULL_TEXT -open class Foo -inline fun g(): T? = null - -inline fun f(block: ()->R?): R? { - return block() -} - -fun main() { - f { g() } -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.kt index 82797f0de8b..db2d5d4315d 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // RENDER_DIAGNOSTICS_FULL_TEXT open class Foo inline fun g(): T? = null diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.fir.kt deleted file mode 100644 index 769d87137c7..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.fir.kt +++ /dev/null @@ -1,7 +0,0 @@ -fun String> g(): T? = null - -fun f(block: () -> R?): R? = block() - -fun main() { - f { g() /* OK, g() is inferred into {Int & String}? */ } -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt index 649762a83c0..90b031bb981 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun String> g(): T? = null fun f(block: () -> R?): R? = block() diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.fir.kt deleted file mode 100644 index e89c4386f64..00000000000 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -// RENDER_DIAGNOSTICS_FULL_TEXT -// !DIAGNOSTICS: -UNUSED_PARAMETER - -class In -class Out - -class A -class B - -fun select(x: K, y: K): K = x -fun genericIn(x: In) {} -fun genericOut(x: Out) {} - -fun test1(a: In, b: In) { - genericIn(select(a, b)) -} - -fun test2(a: Out, b: Out) { - genericOut(select(a, b)) -} diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.kt index 3be8a519d2d..0e66729ace7 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // RENDER_DIAGNOSTICS_FULL_TEXT // !DIAGNOSTICS: -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt index 2e1098043f3..dee9485f70f 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt @@ -9,7 +9,7 @@ fun foo(): T? { } fun main() { - val a: Bar? = foo() + val a: Bar? = foo() } diff --git a/compiler/testData/diagnostics/tests/typeParameters/kt46186.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/kt46186.fir.kt index 4631cbf5291..b6ab6e72dc9 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/kt46186.fir.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/kt46186.fir.kt @@ -39,7 +39,7 @@ inline fun findViewById10(): T where T: View3, T: View5 = null as T fun test10(): I = findViewById10() fun findViewById11(): T = null as T -fun test11(): View4 = findViewById11() +fun test11(): View4 = findViewById11() object Obj { fun findViewById1(): T = null as T @@ -73,7 +73,7 @@ object Obj { fun test10(): View1 = findViewById10() fun findViewById11(): T = null as T - fun test11(): View4 = findViewById11() + fun test11(): View4 = findViewById11() } interface A diff --git a/compiler/testData/diagnostics/tests/when/TypeParameterError.fir.kt b/compiler/testData/diagnostics/tests/when/TypeParameterError.fir.kt deleted file mode 100644 index adcf2aa8801..00000000000 --- a/compiler/testData/diagnostics/tests/when/TypeParameterError.fir.kt +++ /dev/null @@ -1,25 +0,0 @@ -// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection -// FILE: ObjectNode.java - -public interface ObjectNode { - T set(String fieldName, JsonNode value); -} - -// FILE: JsonNode.java - -public class JsonNode - -// FILE: test.kt - -interface JsonObject -class SomeJsonObject() : JsonObject - -fun String.put(value: JsonObject?, node: ObjectNode) { - when (value) { - null -> node.set(this, null) - is SomeJsonObject -> Unit - else -> TODO() - } -} - -fun TODO(): Nothing = null!! diff --git a/compiler/testData/diagnostics/tests/when/TypeParameterError.kt b/compiler/testData/diagnostics/tests/when/TypeParameterError.kt index 126aad27323..15168835ca9 100644 --- a/compiler/testData/diagnostics/tests/when/TypeParameterError.kt +++ b/compiler/testData/diagnostics/tests/when/TypeParameterError.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection // FILE: ObjectNode.java diff --git a/compiler/testData/diagnostics/tests/when/TypeParameterWarning.fir.kt b/compiler/testData/diagnostics/tests/when/TypeParameterWarning.fir.kt deleted file mode 100644 index a9dc0dc2207..00000000000 --- a/compiler/testData/diagnostics/tests/when/TypeParameterWarning.fir.kt +++ /dev/null @@ -1,25 +0,0 @@ -// !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection -// FILE: ObjectNode.java - -public interface ObjectNode { - T set(String fieldName, JsonNode value); -} - -// FILE: JsonNode.java - -public class JsonNode - -// FILE: test.kt - -interface JsonObject -class SomeJsonObject() : JsonObject - -fun String.put(value: JsonObject?, node: ObjectNode) { - when (value) { - null -> node.set(this, null) - is SomeJsonObject -> Unit - else -> TODO() - } -} - -fun TODO(): Nothing = null!! diff --git a/compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt b/compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt index b5923e83e86..32f70979499 100644 --- a/compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt +++ b/compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection // FILE: ObjectNode.java diff --git a/compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt deleted file mode 100644 index b8a49a48691..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -class Expression(val x: T) - -class GreaterOp(val expr1: Expression<*>, val expr2: Expression<*>) - -fun , S : T?> Expression.greater(other: T): GreaterOp = - GreaterOp(this, Expression(other)) - -fun foo(countExpr: Expression) { - countExpr.greater(0) - countExpr.greater("0") - countExpr.greater("0") -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/greater.kt b/compiler/testData/diagnostics/testsWithStdLib/greater.kt index a5e1b0a7e61..e6357112d44 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/greater.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/greater.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class Expression(val x: T) class GreaterOp(val expr1: Expression<*>, val expr2: Expression<*>) diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt index bc0a223c68a..99f51a0a3f8 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt @@ -7,5 +7,5 @@ fun test1(l: List) { val i: Int = l.firstTyped() - val s: String = l.firstTyped() + val s: String = l.firstTyped() }