Check function name in isGenericToArray/isNonGenericToArray
#KT-24427 Fixed
This commit is contained in:
@@ -48,11 +48,11 @@ import org.jetbrains.org.objectweb.asm.Label
|
|||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
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.Textifier
|
||||||
import org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor
|
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.PrintWriter
|
||||||
|
import java.io.StringWriter
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun generateIsCheck(
|
fun generateIsCheck(
|
||||||
@@ -271,6 +271,7 @@ fun Collection<Type>.withVariableIndices(): List<Pair<Int, Type>> = mutableListO
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun FunctionDescriptor.isGenericToArray(): Boolean {
|
fun FunctionDescriptor.isGenericToArray(): Boolean {
|
||||||
|
if (name.asString() != "toArray") return false
|
||||||
if (valueParameters.size != 1 || typeParameters.size != 1) return false
|
if (valueParameters.size != 1 || typeParameters.size != 1) return false
|
||||||
|
|
||||||
val returnType = returnType ?: throw AssertionError(toString())
|
val returnType = returnType ?: throw AssertionError(toString())
|
||||||
@@ -284,6 +285,7 @@ fun FunctionDescriptor.isGenericToArray(): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun FunctionDescriptor.isNonGenericToArray(): Boolean {
|
fun FunctionDescriptor.isNonGenericToArray(): Boolean {
|
||||||
|
if (name.asString() != "toArray") return false
|
||||||
if (!valueParameters.isEmpty() || !typeParameters.isEmpty()) return false
|
if (!valueParameters.isEmpty() || !typeParameters.isEmpty()) return false
|
||||||
|
|
||||||
val returnType = returnType
|
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"
|
||||||
|
}
|
||||||
Generated
+5
@@ -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);
|
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")
|
@TestMetadata("kt3177-toTypedArray.kt")
|
||||||
public void testKt3177_toTypedArray() throws Exception {
|
public void testKt3177_toTypedArray() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
|
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
|
||||||
|
|||||||
+5
@@ -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);
|
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")
|
@TestMetadata("kt3177-toTypedArray.kt")
|
||||||
public void testKt3177_toTypedArray() throws Exception {
|
public void testKt3177_toTypedArray() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
|
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
|
||||||
|
|||||||
+5
@@ -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);
|
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")
|
@TestMetadata("kt3177-toTypedArray.kt")
|
||||||
public void testKt3177_toTypedArray() throws Exception {
|
public void testKt3177_toTypedArray() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
|
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user