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:
committed by
Space Team
parent
84c6333b23
commit
b821009617
+4
-6
@@ -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
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion
|
||||
// FILE: signedToUnsignedConversions_annotation.kt
|
||||
|
||||
package kotlin.internal
|
||||
|
||||
annotation class ImplicitIntegerCoercion
|
||||
|
||||
// FILE: kt61418_test.kt
|
||||
|
||||
import kotlin.internal.ImplicitIntegerCoercion
|
||||
|
||||
fun f(@ImplicitIntegerCoercion x: List<Int>) {}
|
||||
|
||||
fun box(): String {
|
||||
f(listOf(1,2,3))
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+1
-1
@@ -57,7 +57,7 @@ fun test() {
|
||||
|
||||
<!OPT_IN_USAGE!>takeUBytes<!>(IMPLICIT_INT, EXPLICIT_INT, 42u)
|
||||
|
||||
takeLong(IMPLICIT_INT)
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>IMPLICIT_INT<!>)
|
||||
|
||||
takeIntWithoutAnnotation(IMPLICIT_INT)
|
||||
|
||||
|
||||
+6
@@ -49809,6 +49809,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
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 {
|
||||
|
||||
+6
@@ -52713,6 +52713,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
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 {
|
||||
|
||||
+6
@@ -52713,6 +52713,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
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 {
|
||||
|
||||
+5
@@ -42564,6 +42564,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/kt47716.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt61418.kt")
|
||||
public void testKt61418() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/kt61418.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("literalEqualsNullableUnsigned.kt")
|
||||
public void testLiteralEqualsNullableUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/literalEqualsNullableUnsigned.kt");
|
||||
|
||||
+6
@@ -36693,6 +36693,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
||||
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 {
|
||||
|
||||
Generated
+6
@@ -36693,6 +36693,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT
|
||||
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 {
|
||||
|
||||
+6
@@ -36693,6 +36693,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
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 {
|
||||
|
||||
+6
@@ -36693,6 +36693,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
||||
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 {
|
||||
|
||||
@@ -4683,6 +4683,11 @@ if (PlatformInfo.isAppleTarget(project)) {
|
||||
UtilsKt.dependsOnPlatformLibs(it)
|
||||
}
|
||||
|
||||
standaloneTest("interop_objc_kt61441") {
|
||||
source = "interop/objc/kt61441.kt"
|
||||
UtilsKt.dependsOnPlatformLibs(it)
|
||||
}
|
||||
|
||||
|
||||
interopTest("interop_objc_global_initializer") {
|
||||
useGoldenData = true
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
import kotlinx.cinterop.*
|
||||
import platform.Foundation.*
|
||||
import kotlin.test.*
|
||||
|
||||
private fun readString(path: String): String? {
|
||||
// we don't want actually read anything, just testing for compilability
|
||||
if (path != "") {
|
||||
return memScoped {
|
||||
val error = alloc<ObjCObjectVar<NSError?>>()
|
||||
NSString.stringWithContentsOfFile(path, NSUTF8StringEncoding, error.ptr)
|
||||
}
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
readString("")
|
||||
}
|
||||
+6
@@ -40166,6 +40166,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
|
||||
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 {
|
||||
|
||||
+6
@@ -41206,6 +41206,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
|
||||
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 {
|
||||
|
||||
+6
@@ -39647,6 +39647,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
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 {
|
||||
|
||||
+6
@@ -40167,6 +40167,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
|
||||
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 {
|
||||
|
||||
Generated
+6
@@ -36369,6 +36369,12 @@ public class FirWasmCodegenBoxTestGenerated extends AbstractFirWasmCodegenBoxTes
|
||||
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 {
|
||||
|
||||
Generated
+6
@@ -36369,6 +36369,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user