Use manual type mapping in reflection for members from built-ins
There are cases when members deserialized from JVM classes have no JVM signature in the proto. For example, if a member is inherited from a built-in class (such as Map.getOrDefault in some Map implementations), or if a member is synthesized in the compiler front-end and back-end separately (such as enum values/valueOf). In these cases, we'll use the naive type mapping to try to recover the signature. #KT-16616 Fixed #KT-17542 Fixed
This commit is contained in:
+7
-5
@@ -1,12 +1,11 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
// See KT-11258 Incorrect resolution sequence for Java field
|
||||
|
||||
//SHOULD BE deleted after KT-16616 fix
|
||||
// See KT-11258, KT-16616
|
||||
|
||||
import java.util.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
listOf(
|
||||
@@ -22,5 +21,8 @@ fun box(): String {
|
||||
).map {
|
||||
it.members.map(Any::toString)
|
||||
}
|
||||
|
||||
assertEquals(1, Collection<Any>::size.getter(listOf(1)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// IGNORE_BACKEND: JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
enum class E { X, Y, Z }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(11, E::class.members.size)
|
||||
assertEquals("Y", E::name.call(E.Y))
|
||||
assertEquals(2, E::ordinal.call(E.Z))
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// IGNORE_BACKEND: JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
String::class.members
|
||||
assertEquals(2, String::length.call("OK"))
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// IGNORE_BACKEND: JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
enum class E { X, Y, Z }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("fun values(): kotlin.Array<E>", E::values.toString())
|
||||
assertEquals(listOf(E.X, E.Y, E.Z), E::values.call().toList())
|
||||
assertEquals("fun valueOf(kotlin.String): E", E::valueOf.toString())
|
||||
assertEquals(E.Y, E::valueOf.call("Y"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS, NATIVE
|
||||
// FULL_JDK
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import java.util.*
|
||||
|
||||
fun assertToString(s: String, x: Any) {
|
||||
assertEquals(s, x.toString())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertToString("fun kotlin.collections.Map<K, V>.getOrDefault(K, V): V", Map<*, *>::getOrDefault)
|
||||
assertToString("fun java.util.HashMap<K, V>.getOrDefault(K, V): V", HashMap<*, *>::getOrDefault)
|
||||
|
||||
// TODO: uncomment once KT-11754 is fixed
|
||||
// assertToString("", MutableList<*>::removeAt)
|
||||
|
||||
assertToString("fun kotlin.collections.Collection<E>.contains(E): kotlin.Boolean", Collection<*>::contains)
|
||||
assertToString("fun kotlin.collections.Set<E>.contains(E): kotlin.Boolean", Set<*>::contains)
|
||||
|
||||
assertToString("fun kotlin.collections.Collection<E>.isEmpty(): kotlin.Boolean", Collection<*>::isEmpty)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
-30
@@ -1,30 +0,0 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
// See KT-11258 Incorrect resolution sequence for Java field
|
||||
|
||||
// TODO: enable this test on JVM, see KT-16616
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun box(): String {
|
||||
listOf(
|
||||
ArrayList::class,
|
||||
LinkedList::class,
|
||||
AbstractList::class,
|
||||
HashSet::class,
|
||||
TreeSet::class,
|
||||
HashMap::class,
|
||||
TreeMap::class,
|
||||
AbstractMap::class,
|
||||
AbstractMap.SimpleEntry::class
|
||||
).map {
|
||||
it.members.map(Any::toString)
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
Generated
+38
-18
@@ -16408,6 +16408,34 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/builtins")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Builtins extends AbstractIrBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBuiltins() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/builtins"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("collections.kt")
|
||||
public void testCollections() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/builtins/collections.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enumNameOrdinal.kt")
|
||||
public void testEnumNameOrdinal() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/builtins/enumNameOrdinal.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("stringLength.kt")
|
||||
public void testStringLength() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/builtins/stringLength.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/call")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -17129,6 +17157,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/declaredVsInheritedFunctions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enumValuesValueOf.kt")
|
||||
public void testEnumValuesValueOf() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/enumValuesValueOf.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionFromStdlib.kt")
|
||||
public void testFunctionFromStdlib() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/functionFromStdlib.kt");
|
||||
@@ -17581,6 +17614,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/methodsFromAny"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("builtinFunctionsToString.kt")
|
||||
public void testBuiltinFunctionsToString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/builtinFunctionsToString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferencesEqualToCallablesFromAPI.kt")
|
||||
public void testCallableReferencesEqualToCallablesFromAPI() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/callableReferencesEqualToCallablesFromAPI.kt");
|
||||
@@ -18224,24 +18262,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/specialBuiltIns")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class SpecialBuiltIns extends AbstractIrBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInSpecialBuiltIns() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/specialBuiltIns"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("getMembersOfStandardJavaClasses.kt")
|
||||
public void testGetMembersOfStandardJavaClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/supertypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+38
-18
@@ -16408,6 +16408,34 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/builtins")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Builtins extends AbstractBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBuiltins() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/builtins"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("collections.kt")
|
||||
public void testCollections() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/builtins/collections.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enumNameOrdinal.kt")
|
||||
public void testEnumNameOrdinal() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/builtins/enumNameOrdinal.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("stringLength.kt")
|
||||
public void testStringLength() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/builtins/stringLength.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/call")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -17129,6 +17157,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/declaredVsInheritedFunctions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enumValuesValueOf.kt")
|
||||
public void testEnumValuesValueOf() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/enumValuesValueOf.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionFromStdlib.kt")
|
||||
public void testFunctionFromStdlib() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/functionFromStdlib.kt");
|
||||
@@ -17581,6 +17614,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/methodsFromAny"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("builtinFunctionsToString.kt")
|
||||
public void testBuiltinFunctionsToString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/builtinFunctionsToString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferencesEqualToCallablesFromAPI.kt")
|
||||
public void testCallableReferencesEqualToCallablesFromAPI() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/callableReferencesEqualToCallablesFromAPI.kt");
|
||||
@@ -18224,24 +18262,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/specialBuiltIns")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class SpecialBuiltIns extends AbstractBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInSpecialBuiltIns() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/specialBuiltIns"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("getMembersOfStandardJavaClasses.kt")
|
||||
public void testGetMembersOfStandardJavaClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/supertypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+38
-18
@@ -16408,6 +16408,34 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/builtins")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Builtins extends AbstractLightAnalysisModeTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBuiltins() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/builtins"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("collections.kt")
|
||||
public void testCollections() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/builtins/collections.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enumNameOrdinal.kt")
|
||||
public void testEnumNameOrdinal() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/builtins/enumNameOrdinal.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("stringLength.kt")
|
||||
public void testStringLength() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/builtins/stringLength.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/call")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -17129,6 +17157,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/declaredVsInheritedFunctions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enumValuesValueOf.kt")
|
||||
public void testEnumValuesValueOf() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/enumValuesValueOf.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionFromStdlib.kt")
|
||||
public void testFunctionFromStdlib() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/functionFromStdlib.kt");
|
||||
@@ -17581,6 +17614,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/methodsFromAny"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("builtinFunctionsToString.kt")
|
||||
public void testBuiltinFunctionsToString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/builtinFunctionsToString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferencesEqualToCallablesFromAPI.kt")
|
||||
public void testCallableReferencesEqualToCallablesFromAPI() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/callableReferencesEqualToCallablesFromAPI.kt");
|
||||
@@ -18224,24 +18262,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/specialBuiltIns")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class SpecialBuiltIns extends AbstractLightAnalysisModeTest {
|
||||
@TestMetadata("getMembersOfStandardJavaClasses.kt")
|
||||
public void ignoreGetMembersOfStandardJavaClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/specialBuiltIns/getMembersOfStandardJavaClasses.kt");
|
||||
}
|
||||
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInSpecialBuiltIns() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/specialBuiltIns"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/supertypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user