diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt index 9648ab730d7..08fafc76dbf 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt @@ -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( diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1778.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1778.fir.kt index 411aebe6894..9f0640c1d1e 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1778.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1778.fir.kt @@ -8,8 +8,8 @@ import checkSubtype fun main(args : Array) { val x = checkSubtype(args[0]) if(x is java.lang.CharSequence) { - 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 + 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 } }