KT-28405 Fix toString for inline classes with underlying arrays

This commit is contained in:
Dmitry Petrov
2018-12-07 13:06:11 +03:00
parent 500dc11514
commit 45035d3e11
7 changed files with 56 additions and 6 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.psi.KtClassOrObject;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
import org.jetbrains.kotlin.types.KotlinType;
@@ -107,21 +108,22 @@ public class FunctionsFromAnyGeneratorImpl extends FunctionsFromAnyGenerator {
JvmKotlinType type = genOrLoadOnStack(iv, context, propertyDescriptor, 0);
Type asmType = type.getType();
KotlinType kotlinType = type.getKotlinType();
if (asmType.getSort() == Type.ARRAY) {
Type elementType = correctElementType(asmType);
if (elementType.getSort() == Type.OBJECT || elementType.getSort() == Type.ARRAY) {
iv.invokestatic("java/util/Arrays", "toString", "([Ljava/lang/Object;)Ljava/lang/String;", false);
asmType = JAVA_STRING_TYPE;
kotlinType = DescriptorUtilsKt.getBuiltIns(function).getStringType();
}
else {
if (elementType.getSort() != Type.CHAR) {
iv.invokestatic("java/util/Arrays", "toString", "(" + asmType.getDescriptor() + ")Ljava/lang/String;", false);
asmType = JAVA_STRING_TYPE;
}
else if (elementType.getSort() != Type.CHAR) {
iv.invokestatic("java/util/Arrays", "toString", "(" + asmType.getDescriptor() + ")Ljava/lang/String;", false);
asmType = JAVA_STRING_TYPE;
kotlinType = DescriptorUtilsKt.getBuiltIns(function).getStringType();
}
}
genInvokeAppendMethod(iv, asmType, type.getKotlinType(), typeMapper);
genInvokeAppendMethod(iv, asmType, kotlinType, typeMapper);
}
iv.aconst(")");
+23
View File
@@ -0,0 +1,23 @@
// !LANGUAGE: +InlineClasses
// WITH_RUNTIME
// IGNORE_BACKEND: JVM_IR, JS_IR
import kotlin.test.*
inline class TestUIntArrayW(val x: UIntArray)
inline class InlineCharArray(val x: CharArray) {
override fun toString(): String = x.contentToString()
}
inline class TestInlineCharArrayW(val x: InlineCharArray)
fun box(): String {
val t1 = TestUIntArrayW(UIntArray(1)).toString()
if (!t1.startsWith("TestUIntArrayW")) throw AssertionError(t1)
val t2 = TestInlineCharArrayW(InlineCharArray(charArrayOf('a'))).toString()
if (!t2.startsWith("TestInlineCharArrayW")) throw AssertionError(t2)
return "OK"
}
@@ -12120,6 +12120,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
}
@TestMetadata("kt28405.kt")
public void testKt28405() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
@@ -12120,6 +12120,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
}
@TestMetadata("kt28405.kt")
public void testKt28405() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
@@ -12125,6 +12125,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
}
@TestMetadata("kt28405.kt")
public void testKt28405() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
@@ -10490,6 +10490,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
}
@TestMetadata("kt28405.kt")
public void testKt28405() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
@@ -11545,6 +11545,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
}
@TestMetadata("kt28405.kt")
public void testKt28405() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");