K2: add missing checks for integral parameter type on implicit coercion

#KT-61418 fixed
#KT-61442 fixed
#KT-61441 fixed
This commit is contained in:
Ilya Chernikov
2023-08-23 17:31:43 +02:00
committed by Space Team
parent 84c6333b23
commit b821009617
22 changed files with 150 additions and 10 deletions
@@ -21,14 +21,12 @@ import org.jetbrains.kotlin.fir.languageVersionSettings
import org.jetbrains.kotlin.fir.references.*
import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticFunctionSymbol
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.isMarkedWithImplicitIntegerCoercion
import org.jetbrains.kotlin.fir.resolve.calls.getExpectedType
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.approximateDeclarationType
import org.jetbrains.kotlin.fir.resolve.typeAliasForConstructor
import org.jetbrains.kotlin.fir.scopes.getDeclaredConstructors
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
@@ -1059,10 +1057,10 @@ class CallAndReferenceGenerator(
if (!session.languageVersionSettings.supportsFeature(LanguageFeature.ImplicitSignedToUnsignedIntegerConversion)) return this
if (parameter == null || !parameter.isMarkedWithImplicitIntegerCoercion) return this
if (!argument.getExpectedType(parameter).fullyExpandedType(session).isUnsignedTypeOrNullableUnsignedType) return this
fun IrExpression.applyToElement(argument: FirExpression, conversionFunction: IrSimpleFunctionSymbol): IrExpression =
if (argument is FirConstExpression<*> ||
argument is FirNamedArgumentExpression ||
if (argument.isIntegerLiteralOrOperatorCall() ||
argument.calleeReference?.toResolvedCallableSymbol()?.let {
it.resolvedStatus.isConst && it.isMarkedWithImplicitIntegerCoercion
} == true
@@ -52713,6 +52713,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/unsignedTypes/kt47716.kt");
}
@Test
@TestMetadata("kt61418.kt")
public void testKt61418() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/kt61418.kt");
}
@Test
@TestMetadata("literalEqualsNullableUnsigned.kt")
public void testLiteralEqualsNullableUnsigned() throws Exception {
@@ -52713,6 +52713,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/unsignedTypes/kt47716.kt");
}
@Test
@TestMetadata("kt61418.kt")
public void testKt61418() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/kt61418.kt");
}
@Test
@TestMetadata("literalEqualsNullableUnsigned.kt")
public void testLiteralEqualsNullableUnsigned() throws Exception {
@@ -509,12 +509,11 @@ private fun getExpectedTypeWithImplicintIntegerCoercion(
if (!session.languageVersionSettings.supportsFeature(LanguageFeature.ImplicitSignedToUnsignedIntegerConversion)) return null
if (!parameter.isMarkedWithImplicitIntegerCoercion) return null
if (!candidateExpectedType.fullyExpandedType(session).isUnsignedTypeOrNullableUnsignedType) return null
val argumentType =
if (argument.isIntegerLiteralOrOperatorCall()) {
if (candidateExpectedType.fullyExpandedType(session).isUnsignedTypeOrNullableUnsignedType)
argument.resolvedType
else null
argument.resolvedType
} else {
argument.calleeReference?.toResolvedCallableSymbol()?.takeIf {
it.rawStatus.isConst && it.isMarkedWithImplicitIntegerCoercion