Canonical name (#99)
* TEST: enabled testRetainAll * Method resolution spared of annotations and generics * TEST: test for canonical names "interface+generic" added * Methods' canonical names support: - Recursive iteration of method argument types - Arguments in question are delivered from topmost overriden ancestor of this method
This commit is contained in:
committed by
Nikolay Igotti
parent
e9b0ebb95e
commit
90b6a12a5c
+22
-3
@@ -7,16 +7,35 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
|
import org.jetbrains.kotlin.resolve.findOriginalTopMostOverriddenDescriptors
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
|
|
||||||
|
|
||||||
private val symbolNameAnnotation = FqName("kotlin.SymbolName")
|
private val symbolNameAnnotation = FqName("kotlin.SymbolName")
|
||||||
|
|
||||||
|
fun typeToHashString(type: KotlinType): String {
|
||||||
|
if (TypeUtils.isTypeParameter(type)) return "GENERIC"
|
||||||
|
|
||||||
|
var hashString = type.constructor.toString()
|
||||||
|
if (!type.arguments.isEmpty()) {
|
||||||
|
hashString += "<${type.arguments.map {
|
||||||
|
typeToHashString(it.type)
|
||||||
|
}.joinToString(",")}>"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.isMarkedNullable) hashString += "?"
|
||||||
|
return hashString
|
||||||
|
}
|
||||||
|
|
||||||
private val FunctionDescriptor.signature: String
|
private val FunctionDescriptor.signature: String
|
||||||
get() {
|
get() {
|
||||||
// TODO: KotlinType.toString seems to use unqualified names
|
|
||||||
|
|
||||||
val extensionReceiverPart = this.extensionReceiverParameter?.let { "${it.type}." } ?: ""
|
val extensionReceiverPart = this.extensionReceiverParameter?.let { "${it.type}." } ?: ""
|
||||||
|
val actualDescriptor = this.findOriginalTopMostOverriddenDescriptors().firstOrNull() ?: this
|
||||||
|
|
||||||
val argsPart = this.valueParameters.map { it.type }.joinToString(";")
|
val argsPart = actualDescriptor.valueParameters.map {
|
||||||
|
typeToHashString(it.type)
|
||||||
|
}.joinToString(";")
|
||||||
|
|
||||||
// TODO: add return type
|
// TODO: add return type
|
||||||
// (it is not simple because return type can be changed when overriding)
|
// (it is not simple because return type can be changed when overriding)
|
||||||
|
|||||||
@@ -268,6 +268,10 @@ task local_variable(type: UnitKonanTest) {
|
|||||||
source = "codegen/basics/local_variable.kt"
|
source = "codegen/basics/local_variable.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task canonical_name(type: RunKonanTest) {
|
||||||
|
goldValue = "A:foo\nA:qux\n"
|
||||||
|
source = "codegen/basics/canonical_name.kt"
|
||||||
|
}
|
||||||
|
|
||||||
task cast_simple(type: UnitKonanTest) {
|
task cast_simple(type: UnitKonanTest) {
|
||||||
source = "codegen/basics/cast_simple.kt"
|
source = "codegen/basics/cast_simple.kt"
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
interface I<U, T> {
|
||||||
|
fun foo(a: U): T
|
||||||
|
fun qux(a: T): U
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
class A1
|
||||||
|
class A2
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
class A : I<A1, A2> {
|
||||||
|
override fun foo(a: A1): A2 { println("A:foo"); return A2() }
|
||||||
|
override fun qux(a: A2): A1 { println("A:qux"); return A1() }
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
fun <U, V> baz(i: I<U, V>, u: U, v:V) {
|
||||||
|
i.foo(u)
|
||||||
|
i.qux(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
baz<A1, A2>(A(), A1(), A2())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -266,6 +266,7 @@ fun testIteratorRemove() {
|
|||||||
}
|
}
|
||||||
it.next()
|
it.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(makeList135(), a)
|
assertEquals(makeList135(), a)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,8 +289,7 @@ fun main(args : Array<String>) {
|
|||||||
testIterator()
|
testIterator()
|
||||||
testRemove()
|
testRemove()
|
||||||
testRemoveAll()
|
testRemoveAll()
|
||||||
// Fails due to unknown virtual method call!
|
testRetainAll()
|
||||||
// testRetainAll()
|
|
||||||
testEquals()
|
testEquals()
|
||||||
testHashCode()
|
testHashCode()
|
||||||
testToString()
|
testToString()
|
||||||
@@ -299,8 +299,7 @@ fun main(args : Array<String>) {
|
|||||||
testSubListContains()
|
testSubListContains()
|
||||||
testSubListIndexOf()
|
testSubListIndexOf()
|
||||||
testSubListLastIndexOf()
|
testSubListLastIndexOf()
|
||||||
// Fails due to unknown virtual method call!
|
// testIteratorAdd() runtime assert: Throwing is unsupported
|
||||||
// testIteratorAdd()
|
// testIteratorRemove() assertEquals fails
|
||||||
// testIteratorRemove()
|
|
||||||
println("OK")
|
println("OK")
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user