[FIR] Map platform types to Kotlin for equality checks
During the DM it was decided to support such comparisons, if I remember correctly. ^KT-62646
This commit is contained in:
committed by
Space Team
parent
6607c8a056
commit
cd3202ddd4
+5
-5
@@ -24,9 +24,9 @@ import org.jetbrains.kotlin.fir.declarations.utils.isInterface
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.isPrimitiveType
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.scopes.platformClassMapper
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.text
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
|
||||
@@ -321,7 +321,7 @@ private fun ConeKotlinType.isEnum(session: FirSession) = toRegularClassSymbol(se
|
||||
private fun ConeKotlinType.isClass(session: FirSession) = toRegularClassSymbol(session) != null
|
||||
|
||||
private fun ConeKotlinType.toTypeInfo(session: FirSession): TypeInfo {
|
||||
val bounds = collectUpperBounds().map { type -> toKotlinType(type).replaceArgumentsWithStarProjections() }
|
||||
val bounds = collectUpperBounds().map { type -> type.toKotlinTypeIfPlatform(session).replaceArgumentsWithStarProjections() }
|
||||
val type = bounds.ifNotEmpty { ConeTypeIntersector.intersectTypes(session.typeContext, this) }
|
||||
?: session.builtinTypes.nullableAnyType.type
|
||||
val notNullType = type.withNullability(ConeNullability.NOT_NULL, session.typeContext)
|
||||
@@ -338,9 +338,9 @@ private fun ConeKotlinType.toTypeInfo(session: FirSession): TypeInfo {
|
||||
)
|
||||
}
|
||||
|
||||
private fun toKotlinType(type: ConeClassLikeType): ConeClassLikeType {
|
||||
// Type arguments are ignored by design
|
||||
return ConeClassLikeTypeImpl(type.lookupTag, type.typeArguments, type.isNullable)
|
||||
private fun ConeClassLikeType.toKotlinTypeIfPlatform(session: FirSession): ConeClassLikeType {
|
||||
val kotlinClassId = session.platformClassMapper.getCorrespondingKotlinClass(lookupTag.classId)
|
||||
return kotlinClassId?.constructClassLikeType(typeArguments, isNullable, attributes) ?: this
|
||||
}
|
||||
|
||||
private class ArgumentInfo(
|
||||
|
||||
@@ -8,8 +8,8 @@ import checkSubtype
|
||||
fun main(args : Array<String>) {
|
||||
val x = checkSubtype<Any>(args[0])
|
||||
if(x is <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.CharSequence<!>) {
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!>) x.length else x.length() // OK
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!> || <!EQUALITY_NOT_APPLICABLE_WARNING!>"b" == x<!>) x.length else x.length() // <– THEN ERROR
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!> && "a" == x) x.length else x.length() // <– ELSE ERROR
|
||||
if ("a" == x) x.length else x.length() // OK
|
||||
if ("a" == x || "b" == x) x.length else x.length() // <– THEN ERROR
|
||||
if ("a" == x && "a" == x) x.length else x.length() // <– ELSE ERROR
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user