Fix JVM signatures involving multi-dimensional array types
Apparently ASM's Type#getElementType returns the type of the array even if it's multi-dimensional, so the loop was incorrect
This commit is contained in:
@@ -257,15 +257,11 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
public JvmProtoBuf.JvmType type(@NotNull Type givenType) {
|
||||
JvmProtoBuf.JvmType.Builder builder = JvmProtoBuf.JvmType.newBuilder();
|
||||
|
||||
int arrayDimension = 0;
|
||||
Type type = givenType;
|
||||
while (type.getSort() == Type.ARRAY) {
|
||||
arrayDimension++;
|
||||
if (type.getSort() == Type.ARRAY) {
|
||||
builder.setArrayDimension(type.getDimensions());
|
||||
type = type.getElementType();
|
||||
}
|
||||
if (arrayDimension != 0) {
|
||||
builder.setArrayDimension(arrayDimension);
|
||||
}
|
||||
|
||||
if (type.getSort() == Type.OBJECT) {
|
||||
FqName fqName = internalNameToFqName(type.getInternalName());
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
class A {
|
||||
class B(val result: String)
|
||||
|
||||
var p: A.B? = null
|
||||
var q: Array<Array<A.B>>? = null
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
(A::q).set(a, array(array(A.B("array"))))
|
||||
if (a.q!![0][0].result != "array") return "Fail array"
|
||||
|
||||
(A::p).set(a, A.B("OK"))
|
||||
return a.p!!.result
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//ALLOW_AST_ACCESS
|
||||
package test
|
||||
|
||||
annotation class Anno(val s: String)
|
||||
|
||||
trait T {
|
||||
Anno("foo")
|
||||
fun foo(): Array<Array<Array<T>>>
|
||||
|
||||
Anno("bar")
|
||||
val bar: Array<Array<BooleanArray>>
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package test
|
||||
|
||||
internal final annotation class Anno : kotlin.Annotation {
|
||||
/*primary*/ public constructor Anno(/*0*/ s: kotlin.String)
|
||||
internal final val s: kotlin.String
|
||||
internal final fun <get-s>(): kotlin.String
|
||||
}
|
||||
|
||||
internal trait T {
|
||||
test.Anno(s = "bar": kotlin.String) internal abstract val bar: kotlin.Array<kotlin.Array<kotlin.BooleanArray>>
|
||||
internal abstract fun <get-bar>(): kotlin.Array<kotlin.Array<kotlin.BooleanArray>>
|
||||
test.Anno(s = "foo": kotlin.String) internal abstract fun foo(): kotlin.Array<kotlin.Array<kotlin.Array<test.T>>>
|
||||
}
|
||||
+6
@@ -3038,6 +3038,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyOfNestedClassAndArrayType.kt")
|
||||
public void testPropertyOfNestedClassAndArrayType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/properties/propertyOfNestedClassAndArrayType.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleGetProperties.kt")
|
||||
public void testSimpleGetProperties() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/properties/simpleGetProperties.kt");
|
||||
|
||||
@@ -1959,6 +1959,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTestCompiledKotlin(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MultiDimensionalArrayMethod.kt")
|
||||
public void testMultiDimensionalArrayMethod() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/MultiDimensionalArrayMethod.kt");
|
||||
doTestCompiledKotlin(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SimpleAnnotation.kt")
|
||||
public void testSimpleAnnotation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/SimpleAnnotation.kt");
|
||||
|
||||
+6
@@ -93,6 +93,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MultiDimensionalArrayMethod.kt")
|
||||
public void testMultiDimensionalArrayMethod() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/MultiDimensionalArrayMethod.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SimpleAnnotation.kt")
|
||||
public void testSimpleAnnotation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/SimpleAnnotation.kt");
|
||||
|
||||
-1
@@ -46,7 +46,6 @@ public val Class<*>.desc: String
|
||||
if (this == Void.TYPE) return "V"
|
||||
// This is a clever exploitation of a format returned by Class.getName(): for arrays, it's almost an internal name,
|
||||
// but with '.' instead of '/'
|
||||
// TODO: ensure there are tests on arrays of nested classes, multi-dimensional arrays, etc.
|
||||
return createArrayType().getName().substring(1).replace('.', '/')
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,6 @@ abstract class KCallableContainerImpl {
|
||||
arrayDimension: Int = type.getArrayDimension()
|
||||
): Class<*> {
|
||||
if (arrayDimension > 0) {
|
||||
// TODO: test multi-dimensional arrays
|
||||
return loadJvmType(type, nameResolver, classLoader, arrayDimension - 1).createArrayType()
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,12 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MultiDimensionalArrayMethod.kt")
|
||||
public void testMultiDimensionalArrayMethod() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/MultiDimensionalArrayMethod.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SimpleAnnotation.kt")
|
||||
public void testSimpleAnnotation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/SimpleAnnotation.kt");
|
||||
|
||||
Reference in New Issue
Block a user