From 86e175bbf1d0ba27d5db853110138e7417a63524 Mon Sep 17 00:00:00 2001 From: "Anastasia.Nekrasova" Date: Thu, 26 Oct 2023 11:31:08 +0300 Subject: [PATCH] [K2] Disappeared KCLASS_WITH_NULLABLE_TYPE_PARAMETER_IN_SIGNATURE ^KT-59992 --- ...rKClassWithIncorrectTypeArgumentChecker.kt | 19 ++++++++++++++----- .../kClassInSignature.fir.kt | 5 ++++- .../declarationChecks/kClassInSignature.kt | 3 +++ .../declarationChecks/kClassInSignature.txt | 2 ++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirKClassWithIncorrectTypeArgumentChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirKClassWithIncorrectTypeArgumentChecker.kt index a441c4147d3..6c9b92a2414 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirKClassWithIncorrectTypeArgumentChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirKClassWithIncorrectTypeArgumentChecker.kt @@ -29,12 +29,21 @@ object FirKClassWithIncorrectTypeArgumentChecker : FirCallableDeclarationChecker val source = declaration.source ?: return if (source.kind is KtFakeSourceElementKind) return - val returnType = declaration.returnTypeRef.coneType - if (!returnType.isKClassTypeWithErrorOrNullableArgument(context.session.typeContext)) return + val typeArgumentsWithWrongType = mutableListOf() - val typeArgument = (returnType.typeArguments[0] as ConeKotlinTypeProjection).type - typeArgument.typeParameterFromError?.let { - reporter.reportOn(source, FirErrors.KCLASS_WITH_NULLABLE_TYPE_PARAMETER_IN_SIGNATURE, it, context) + val returnType = declaration.returnTypeRef.coneType + if (returnType.isKClassTypeWithErrorOrNullableArgument(context.session.typeContext)) typeArgumentsWithWrongType.add(returnType) + + returnType.typeArguments.forEach { + val type = it.type ?: return@forEach + if (type.isKClassTypeWithErrorOrNullableArgument(context.session.typeContext)) + typeArgumentsWithWrongType.add(type) + } + + if (typeArgumentsWithWrongType.isEmpty()) return + typeArgumentsWithWrongType.forEach { + val typeParameterFromError = (it.typeArguments[0] as? ConeKotlinTypeProjection)?.type?.typeParameterFromError ?: return@forEach + reporter.reportOn(source, FirErrors.KCLASS_WITH_NULLABLE_TYPE_PARAMETER_IN_SIGNATURE, typeParameterFromError, context) } } diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.fir.kt index 25916061f1b..18704a0ad3b 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.fir.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.fir.kt @@ -6,7 +6,7 @@ fun test2() = T::class val test3 = T::class val test4 get() = T::class -fun test5() = listOf(T::class) +fun test5() = listOf(T::class) fun test6(): kotlin.reflect.KClass<T> = T::class fun test7(): kotlin.reflect.KClass<*> = T::class @@ -14,6 +14,9 @@ fun test8() = String?::class fun test9() where T : Any?, T : Comparable = T::class +fun mapOf(e: T, b: K): Map = null!! +fun test10() = mapOf(T::class, K::class) + fun listOf(e: T): List = null!! fun locals() { diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.kt b/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.kt index 20c1a573561..accb0425361 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.kt @@ -14,6 +14,9 @@ fun test8() = String?::class fun test9() where T : Any?, T : Comparable = T::class +fun mapOf(e: T, b: K): Map = null!! +fun test10() = mapOf(T::class, K::class) + fun listOf(e: T): List = null!! fun locals() { diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.txt b/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.txt index ccefa98daaa..1bedc7bce43 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.txt +++ b/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.txt @@ -4,7 +4,9 @@ public val test3: kotlin.reflect.KClass public val test4: kotlin.reflect.KClass public fun listOf(/*0*/ e: T): kotlin.collections.List public fun locals(): kotlin.Unit +public fun mapOf(/*0*/ e: T, /*1*/ b: K): kotlin.collections.Map public fun test1(): kotlin.reflect.KClass +public fun test10(): kotlin.collections.Map, kotlin.reflect.KClass> public fun test2(): kotlin.reflect.KClass public fun test5(): kotlin.collections.List> public fun test6(): kotlin.reflect.KClass