[FIR] Fix false negative TYPE_PARAMETER_AS_REIFIED_ARRAY
... in presence of typealiases. #KT-61921
This commit is contained in:
committed by
Space Team
parent
f5f77d43bf
commit
36c0c2c76b
+10
-4
@@ -11,9 +11,11 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.chooseFactory
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.fullyExpandedClassId
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
@@ -58,11 +60,15 @@ object FirReifiedChecker : FirQualifiedAccessExpressionChecker() {
|
||||
isExplicit: Boolean,
|
||||
isArray: Boolean,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
reporter: DiagnosticReporter,
|
||||
) {
|
||||
if (typeArgument.classId == StandardClassIds.Array) {
|
||||
val nestedTypeArgument = typeArgument.typeArguments[0].type ?: return
|
||||
checkArgumentAndReport(nestedTypeArgument, source, isExplicit, isArray = true, context, reporter)
|
||||
val fullyExpandedType = typeArgument.fullyExpandedType(context.session)
|
||||
if (fullyExpandedType.classId == StandardClassIds.Array) {
|
||||
// Type aliases can transform type arguments arbitrarily (drop, nest, etc...).
|
||||
// Therefore, we check the arguments of the expanded type, not the ones that went into the type alias.
|
||||
fullyExpandedType.typeArguments.forEach {
|
||||
if (it is ConeKotlinType) checkArgumentAndReport(it, source, isExplicit, isArray = true, context, reporter)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -4,10 +4,16 @@
|
||||
|
||||
inline fun <reified T> foo() {}
|
||||
|
||||
typealias TA<T, R> = Array<R>
|
||||
|
||||
fun <T> bar() {
|
||||
foo<<!TYPE_PARAMETER_AS_REIFIED!>T<!>>()
|
||||
foo<<!TYPE_PARAMETER_AS_REIFIED_ARRAY_ERROR!>Array<T><!>>()
|
||||
foo<<!TYPE_PARAMETER_AS_REIFIED_ARRAY_ERROR!>Array<Array<T>><!>>()
|
||||
foo<TA<T, String>>()
|
||||
foo<<!TYPE_PARAMETER_AS_REIFIED_ARRAY_ERROR!>TA<String, T><!>>()
|
||||
foo<TA<TA<String, T>, String>>()
|
||||
foo<<!TYPE_PARAMETER_AS_REIFIED_ARRAY_ERROR!>TA<String, TA<String, T>><!>>()
|
||||
foo<Array<Int>>()
|
||||
foo<Array<Array<Int>>>()
|
||||
foo<IntArray>()
|
||||
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> bar(): kotlin.Unit
|
||||
public inline fun </*0*/ reified T> foo(): kotlin.Unit
|
||||
public fun test(/*0*/ x: kotlin.Array<kotlin.String>, /*1*/ y: kotlin.Array<*>): kotlin.Unit
|
||||
Reference in New Issue
Block a user