[IR] Filter chars and codePoints from allowed to interpret function
These two functions apparently are represented in Kotlin as methods of `kotlin.String`. Because of that we accidentally treated them as builtins. To also minimize such cases, added filtration by return type. We are allowing to interpret only these functions that have primitive or unsigned return type. #KT-57028 Fixed
This commit is contained in:
+6
@@ -28333,6 +28333,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt57028.kt")
|
||||
public void testKt57028() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt57028.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt57313.kt")
|
||||
public void testKt57313() throws Exception {
|
||||
|
||||
+6
@@ -28333,6 +28333,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt57028.kt")
|
||||
public void testKt57028() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt57028.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt57313.kt")
|
||||
public void testKt57313() throws Exception {
|
||||
|
||||
+7
-1
@@ -51,7 +51,10 @@ enum class EvaluationMode(protected val mustCheckBody: Boolean) {
|
||||
|
||||
ONLY_BUILTINS(mustCheckBody = false) {
|
||||
private val forbiddenMethodsOnPrimitives = setOf("inc", "dec", "rangeTo", "rangeUntil", "hashCode")
|
||||
private val forbiddenMethodsOnStrings = setOf("subSequence", "hashCode", "<init>")
|
||||
private val forbiddenMethodsOnStrings = setOf(
|
||||
"subSequence", "hashCode", "<init>",
|
||||
"chars", "codePoints" // from java.lang.CharSequence; they are represented as member declarations from "kotlin.String"
|
||||
)
|
||||
private val allowedExtensionFunctions = setOf(
|
||||
"kotlin.floorDiv", "kotlin.mod", "kotlin.NumbersKt.floorDiv", "kotlin.NumbersKt.mod", "kotlin.<get-code>"
|
||||
)
|
||||
@@ -65,6 +68,9 @@ enum class EvaluationMode(protected val mustCheckBody: Boolean) {
|
||||
override fun canEvaluateFunction(function: IrFunction, context: IrCall?): Boolean {
|
||||
if (function.property?.isConst == true) return true
|
||||
|
||||
val returnType = function.returnType
|
||||
if (!returnType.isPrimitiveType() && !returnType.isString() && !returnType.isUnsignedType()) return false
|
||||
|
||||
val fqName = function.fqNameWhenAvailable?.asString()
|
||||
val parent = function.parentClassOrNull
|
||||
val parentType = parent?.defaultType
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_STDLIB
|
||||
// FULL_JDK
|
||||
|
||||
// java.lang.NoSuchMethodError: java.lang.String.chars
|
||||
// IGNORE_BACKEND: ANDROID
|
||||
import kotlin.streams.toList
|
||||
|
||||
fun box(): String {
|
||||
val shoulNotBeEveluated1 = "HelloWorld".chars()
|
||||
val shoulNotBeEveluated2 = "HelloWorld".codePoints()
|
||||
val shoulNotBeEveluated3 = "HelloWorld".chars().toList().groupBy { it }.map { it.key to it.value.size }.joinToString().also(::println)
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -27199,6 +27199,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt57028.kt")
|
||||
public void testKt57028() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt57028.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/intrinsicConst")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+6
@@ -28333,6 +28333,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt57028.kt")
|
||||
public void testKt57028() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt57028.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt57313.kt")
|
||||
public void testKt57313() throws Exception {
|
||||
|
||||
+6
@@ -28333,6 +28333,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt57028.kt")
|
||||
public void testKt57028() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt57028.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt57313.kt")
|
||||
public void testKt57313() throws Exception {
|
||||
|
||||
+5
@@ -22952,6 +22952,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt57028.kt")
|
||||
public void testKt57028() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt57028.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/intrinsicConst")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user