Check function name in isGenericToArray/isNonGenericToArray

#KT-24427 Fixed
This commit is contained in:
Alexander Udalov
2018-05-24 15:16:57 +02:00
parent 92d848b6e6
commit 9c5256434c
5 changed files with 33 additions and 2 deletions
@@ -48,11 +48,11 @@ import org.jetbrains.org.objectweb.asm.Label
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.org.objectweb.asm.commons.Method
import org.jetbrains.org.objectweb.asm.tree.MethodNode
import org.jetbrains.org.objectweb.asm.util.Textifier
import org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor
import org.jetbrains.org.objectweb.asm.tree.MethodNode
import java.io.StringWriter
import java.io.PrintWriter
import java.io.StringWriter
import java.util.*
fun generateIsCheck(
@@ -271,6 +271,7 @@ fun Collection<Type>.withVariableIndices(): List<Pair<Int, Type>> = mutableListO
}
fun FunctionDescriptor.isGenericToArray(): Boolean {
if (name.asString() != "toArray") return false
if (valueParameters.size != 1 || typeParameters.size != 1) return false
val returnType = returnType ?: throw AssertionError(toString())
@@ -284,6 +285,7 @@ fun FunctionDescriptor.isGenericToArray(): Boolean {
}
fun FunctionDescriptor.isNonGenericToArray(): Boolean {
if (name.asString() != "toArray") return false
if (!valueParameters.isEmpty() || !typeParameters.isEmpty()) return false
val returnType = returnType
@@ -0,0 +1,14 @@
// TARGET_BACKEND: JVM
// FULL_JDK
// WITH_RUNTIME
import java.lang.reflect.Modifier
abstract class A : Collection<String> {
protected fun <T> foo(x: Array<T>): Array<T> = x
}
fun box(): String {
val method = A::class.java.declaredMethods.single { it.name == "foo" }
return if (Modifier.isProtected(method.modifiers)) "OK" else "Fail: $method"
}
@@ -20585,6 +20585,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/toArray"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("incorrectToArrayDetection.kt")
public void testIncorrectToArrayDetection() throws Exception {
runTest("compiler/testData/codegen/box/toArray/incorrectToArrayDetection.kt");
}
@TestMetadata("kt3177-toTypedArray.kt")
public void testKt3177_toTypedArray() throws Exception {
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
@@ -20585,6 +20585,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/toArray"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("incorrectToArrayDetection.kt")
public void testIncorrectToArrayDetection() throws Exception {
runTest("compiler/testData/codegen/box/toArray/incorrectToArrayDetection.kt");
}
@TestMetadata("kt3177-toTypedArray.kt")
public void testKt3177_toTypedArray() throws Exception {
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
@@ -20585,6 +20585,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/toArray"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("incorrectToArrayDetection.kt")
public void testIncorrectToArrayDetection() throws Exception {
runTest("compiler/testData/codegen/box/toArray/incorrectToArrayDetection.kt");
}
@TestMetadata("kt3177-toTypedArray.kt")
public void testKt3177_toTypedArray() throws Exception {
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");