KT-22714 Avoid to generate unecessary checkcast
- StackValue already avoid to generate checkcast from a type or an array to java.lang.Object. Add a new case to avoid to generate a checkcast from an array to an array of java.lang.Object when arrays have the same dimensions. Fix of https://youtrack.jetbrains.com/issue/KT-22714
This commit is contained in:
committed by
Dmitry Petrov
parent
0ecb3afdf7
commit
9274241c0e
@@ -0,0 +1,16 @@
|
||||
// JVM_TARGET: 1.8
|
||||
|
||||
fun <T> Array<T>.getLength(): Int {
|
||||
return this.size
|
||||
}
|
||||
|
||||
fun Any.getLength() =
|
||||
if (this is Array<*>) size else -1
|
||||
|
||||
fun box(): String {
|
||||
val array1: Array<String> = arrayOf("1", "2", "3")
|
||||
val array2: Any = arrayOf("1", "2", "3")
|
||||
if (array1.getLength() + array2.getLength() != 6)
|
||||
return "FAILURE"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// JVM_TARGET: 1.8
|
||||
|
||||
fun <T> Array<T>.getLength(): Int {
|
||||
return this.size
|
||||
}
|
||||
|
||||
fun Any.getLength() =
|
||||
if (this is Array<*>) size else -1
|
||||
|
||||
fun testCheckcast1(): Int {
|
||||
val array1: Array<String> = arrayOf("1", "2", "3")
|
||||
val array2: Any = arrayOf("1", "2", "3")
|
||||
return array1.getLength() + array2.getLength()
|
||||
}
|
||||
|
||||
// 1 CHECKCAST
|
||||
Generated
+15
@@ -333,6 +333,21 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/java8/box/jvm8/checkcast")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Checkcast extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInCheckcast() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/java8/box/jvm8/checkcast"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("kt22714.kt")
|
||||
public void testKt22714() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/checkcast/kt22714.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/java8/box/jvm8/defaults")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Generated
+15
@@ -25,6 +25,21 @@ public class BytecodeTextJava8TestGenerated extends AbstractBytecodeTextTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/java8/bytecodeText"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/java8/bytecodeText/checkcast")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Checkcast extends AbstractBytecodeTextTest {
|
||||
public void testAllFilesPresentInCheckcast() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/java8/bytecodeText/checkcast"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("kt22714.kt")
|
||||
public void testKt22714() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/bytecodeText/checkcast/kt22714.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/java8/bytecodeText/hashCode")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user