[FIR] Revert changes related to reporting WRONG_NUMBER_OF_TYPE_ARGUMENTS for type aliases

This commit is contained in:
Ivan Kochurkin
2021-09-20 20:46:07 +03:00
committed by TeamCityServer
parent 05b91d37a7
commit a509e819b5
6 changed files with 15 additions and 71 deletions
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeUnexpectedTypeArgumentsError
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.calls.fullyExpandedClass
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeOuterClassArgumentsRequired
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedQualifierError
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnsupportedDynamicType
@@ -235,12 +234,12 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
}
}
if (symbol is FirClassLikeSymbol<*>) {
if (symbol is FirRegularClassSymbol) {
val isPossibleBareType = areBareTypesAllowed && allTypeArguments.isEmpty()
if (!isPossibleBareType) {
val actualSubstitutor = substitutor ?: ConeSubstitutor.Empty
val originalTypeParameters = collectTypeParameters(symbol)
val originalTypeParameters = symbol.fir.typeParameters
val (typeParametersAlignedToQualifierParts, outerDeclarations) = getClassesAlignedToQualifierParts(
symbol,
@@ -252,7 +251,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
when (symbol) {
is FirTypeAliasSymbol ->
outerDeclarations.sumOf { it?.let { d -> getActualTypeParametersCount(d) } ?: 0 }
else -> (symbol as FirClassSymbol<*>).typeParameterSymbols.size
else -> symbol.typeParameterSymbols.size
}
for ((typeParameterIndex, typeParameter) in originalTypeParameters.withIndex()) {
@@ -322,45 +321,6 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
}
}
private fun collectTypeParameters(symbol: FirClassLikeSymbol<*>): List<FirTypeParameterRef> {
if (symbol is FirClassSymbol<*>) {
return symbol.fir.typeParameters
}
require(symbol is FirTypeAliasSymbol)
val typeAliasFir = symbol.fir
val typeAliasTypeParameters = typeAliasFir.typeParameters.toMutableList()
val fullyExpandedClass = typeAliasFir.fullyExpandedClass(session)
val newTypeParameters = if (fullyExpandedClass != null) { // TODO: Should not be null, move to resolver?
val expandedTypeRef = typeAliasFir.expandedTypeRef
fun checkTypeArguments(typeArgument: ConeTypeProjection) {
when (typeArgument) {
is ConeTypeParameterType -> typeAliasTypeParameters.removeIf { it.symbol == typeArgument.lookupTag.symbol }
is ConeClassLikeType -> {
for (subTypeArgument in typeArgument.typeArguments) {
checkTypeArguments(subTypeArgument)
}
}
is ConeKotlinTypeProjection -> checkTypeArguments(typeArgument.type)
else -> {
}
}
}
checkTypeArguments(expandedTypeRef.coneType)
fullyExpandedClass.typeParameters.toMutableList()
} else {
mutableListOf()
}
for (typeParameter in typeAliasTypeParameters) {
newTypeParameters.add(typeParameter)
}
return newTypeParameters
}
@OptIn(SymbolInternals::class)
private fun getClassesAlignedToQualifierParts(
symbol: FirClassLikeSymbol<*>,
@@ -393,7 +353,8 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
currentClassLikeDeclaration = reversedOuterClasses[index]
val typeParameters = when (currentClassLikeDeclaration) {
is FirTypeAlias -> currentClassLikeDeclaration.typeParameters
else -> (currentClassLikeDeclaration as? FirClass)?.typeParameters
is FirClass -> currentClassLikeDeclaration.typeParameters
else -> null
}
if (currentClassLikeDeclaration != null && typeParameters != null) {
for (typeParameter in typeParameters) {
@@ -26,9 +26,9 @@ fun <T> test5(x: Outer<T>.GenericNestedAlias<Int>) = x
fun <T> test6(x: Outer<Int>.GenericNestedAlias<T>) = x
fun test7(x: Outer.GenericNestedAlias<Int>) = x
fun <T> test8(x: Outer.GenericNestedAlias<T>) = x
fun test9(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Outer<!>.InnerAlias) = x
fun test9(x: Outer.InnerAlias) = x
fun test10(x: Outer<Int>.InnerAlias) = x
fun <T> test11(x: Outer<T>.InnerAlias) = x
fun test12(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Outer<!>.GenericInnerAlias<Int>) = x
fun test12(x: Outer.GenericInnerAlias<Int>) = x
fun test13(x: Outer<Int>.GenericInnerAlias<Int>) = x
fun <T> test14(x: Outer<T>.GenericInnerAlias<Int>) = x
@@ -1,24 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY
class C<T> {
inner class D
typealias DA = D
typealias SDA = C<Int>.D
typealias TSDA = C<T>.D
typealias TC = C<T>
typealias SSDA = C<*>.D
typealias SSC = C<*>
}
fun test1(x: C<Int>.DA) = x
fun test2(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>C<!>.SDA) = x
fun test3(x: C<Int>.TSDA) = x
fun test4(x: C<Int>.TC) = x
fun test5(x: C<*>.DA) = x
fun test6(x: C<*>.TSDA) = x
fun test7(x: C<*>.TC) = x
fun test8(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>C<!>.SSDA) = x
fun test9(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>C<!>.SSC) = x
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY
class C<T> {
@@ -0,0 +1,7 @@
open class Ref<T>(var x: T)
typealias R<T> = Ref<T>
// Type inference SHOULD NOT work for type alias constructor in supertypes list
class Test1 : R(0)
class Test2 : R<Int>(0)
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
open class Ref<T>(var x: T)
typealias R<T> = Ref<T>