Additional tests and fixes for function name mangling

This commit is contained in:
Dmitry Petrov
2018-08-22 15:04:44 +03:00
committed by Ilya Gorbunov
parent 99498eb7b8
commit a205019156
11 changed files with 55 additions and 16 deletions
@@ -54,16 +54,6 @@ private fun md5radix36string(signatureForMangling: String): String {
fun KotlinType.isTypeParameterWithInlineClassUpperBound(): Boolean {
val descriptor = constructor.declarationDescriptor as? TypeParameterDescriptor ?: return false
return descriptor.isWithInlineClassUpperBoundInner(hashSetOf(descriptor))
}
private fun TypeParameterDescriptor.isWithInlineClassUpperBoundInner(visited: MutableSet<TypeParameterDescriptor>): Boolean {
for (type in typeConstructor.supertypes) {
if (type.isInlineClassType()) return true
val typeParameterDescriptor = type.constructor.declarationDescriptor as? TypeParameterDescriptor ?: continue
if (!visited.add(typeParameterDescriptor)) continue
if (typeParameterDescriptor.isWithInlineClassUpperBoundInner(visited)) return true
}
return false
val bound = getRepresentativeUpperBound(descriptor)
return bound.isInlineClassType() || bound.isTypeParameterWithInlineClassUpperBound()
}
@@ -11,6 +11,10 @@ fun Id.test() {
if (id != "OK") throw AssertionError()
}
fun Id?.test() {
if (this != null) throw AssertionError()
}
fun Name.test() {
if (name != "OK") throw AssertionError()
}
@@ -41,6 +45,7 @@ class Outer {
fun box(): String {
Id("OK").test()
null.test()
Name("OK").test()
test(Password("OK"))
@@ -0,0 +1,21 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR, JS, JS_IR
// WITH_REFLECT
import kotlin.reflect.KFunction
import kotlin.reflect.jvm.javaMethod
import kotlin.test.*
inline class InlineClass1(val s: String)
inline class InlineClass2(val n: Number)
fun <T : InlineClass1, U : InlineClass2> foo(t: T, u: U) {}
fun box(): String {
val fooRef: (InlineClass1, InlineClass2) -> Unit = ::foo
val fooMethod = (fooRef as KFunction<*>).javaMethod!!
assertEquals("[T, U]", fooMethod.genericParameterTypes.asList().toString())
return "OK"
}
@@ -1,5 +1,5 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR, JS, JS_IR
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
import kotlin.test.*
@@ -3,8 +3,6 @@
// WITH_REFLECT
import kotlin.test.*
import kotlin.test.*
inline class S(val string: String)
fun test(s: S) {
@@ -1,5 +1,5 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR, JS, JS_IR
// IGNORE_BACKEND: JVM_IR, JS
// WITH_RUNTIME
import kotlin.test.*
@@ -11790,6 +11790,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericFunctionsDoNotClash.kt");
}
@TestMetadata("genericSignatureOfFunctionWithMangledName.kt")
public void testGenericSignatureOfFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericSignatureOfFunctionWithMangledName.kt");
}
@TestMetadata("localClassInFunctionWithMangledName.kt")
public void testLocalClassInFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/localClassInFunctionWithMangledName.kt");
@@ -11790,6 +11790,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericFunctionsDoNotClash.kt");
}
@TestMetadata("genericSignatureOfFunctionWithMangledName.kt")
public void testGenericSignatureOfFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericSignatureOfFunctionWithMangledName.kt");
}
@TestMetadata("localClassInFunctionWithMangledName.kt")
public void testLocalClassInFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/localClassInFunctionWithMangledName.kt");
@@ -11790,6 +11790,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericFunctionsDoNotClash.kt");
}
@TestMetadata("genericSignatureOfFunctionWithMangledName.kt")
public void testGenericSignatureOfFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericSignatureOfFunctionWithMangledName.kt");
}
@TestMetadata("localClassInFunctionWithMangledName.kt")
public void testLocalClassInFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/localClassInFunctionWithMangledName.kt");
@@ -10340,6 +10340,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericFunctionsDoNotClash.kt");
}
@TestMetadata("genericSignatureOfFunctionWithMangledName.kt")
public void testGenericSignatureOfFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericSignatureOfFunctionWithMangledName.kt");
}
@TestMetadata("localClassInFunctionWithMangledName.kt")
public void testLocalClassInFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/localClassInFunctionWithMangledName.kt");
@@ -11400,6 +11400,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericFunctionsDoNotClash.kt");
}
@TestMetadata("genericSignatureOfFunctionWithMangledName.kt")
public void testGenericSignatureOfFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/genericSignatureOfFunctionWithMangledName.kt");
}
@TestMetadata("localClassInFunctionWithMangledName.kt")
public void testLocalClassInFunctionWithMangledName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionNameMangling/localClassInFunctionWithMangledName.kt");