[FIR] Expand typealiases before checking type of class literal

This commit is contained in:
Dmitriy Novozhilov
2023-06-08 13:53:33 +03:00
committed by Space Team
parent 6c7eb0167c
commit 0f0f0d604f
2 changed files with 9 additions and 6 deletions
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.references.toResolvedTypeParameterSymbol
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.scopes.impl.toConeType
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
@@ -73,7 +74,7 @@ object FirClassLiteralChecker : FirGetClassCallChecker() {
if (argument !is FirResolvedQualifier) return
// TODO: differentiate RESERVED_SYNTAX_IN_CALLABLE_REFERENCE_LHS
if (argument.typeArguments.isNotEmpty() && !argument.typeRef.coneType.isAllowedInClassLiteral(context)) {
if (argument.typeArguments.isNotEmpty() && !argument.typeRef.coneType.fullyExpandedType(context.session).isAllowedInClassLiteral(context)) {
val symbol = argument.symbol
symbol?.lazyResolveToPhase(FirResolvePhase.TYPES)
@OptIn(SymbolInternals::class)
@@ -81,7 +82,9 @@ object FirClassLiteralChecker : FirGetClassCallChecker() {
// Among type parameter references, only count actual type parameter while discarding [FirOuterClassTypeParameterRef]
val expectedTypeArgumentSize = typeParameters?.count { it is FirTypeParameter } ?: 0
if (expectedTypeArgumentSize != argument.typeArguments.size) {
// Will be reported as WRONG_NUMBER_OF_TYPE_ARGUMENTS
if (symbol != null) {
reporter.reportOn(argument.source, FirErrors.WRONG_NUMBER_OF_TYPE_ARGUMENTS, expectedTypeArgumentSize, symbol, context)
}
return
}
reporter.reportOn(source, FirErrors.CLASS_LITERAL_LHS_NOT_A_CLASS, context)
@@ -26,7 +26,7 @@ fun test() {
Some::class
SomeAlias::class
<!CLASS_LITERAL_LHS_NOT_A_CLASS!>SomeAlias<String>::class<!>
SomeAlias<String>::class
MyPair::class
<!CLASS_LITERAL_LHS_NOT_A_CLASS!>MyPair<Int, Int>::class<!>
@@ -50,12 +50,12 @@ fun test() {
<!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<*>::class<!>
SimpleArrayAlias::class
<!CLASS_LITERAL_LHS_NOT_A_CLASS!>SimpleArrayAlias<Int>::class<!>
SimpleArrayAlias<Int>::class
<!CLASS_LITERAL_LHS_NOT_A_CLASS!>SimpleArrayAlias<*>::class<!>
SpecificArrayAlias::class
UnusedArrayAlias::class
<!CLASS_LITERAL_LHS_NOT_A_CLASS!>UnusedArrayAlias<Int>::class<!>
<!CLASS_LITERAL_LHS_NOT_A_CLASS!>UnusedArrayAlias<*>::class<!>
UnusedArrayAlias<Int>::class
UnusedArrayAlias<*>::class
}