Minor, rename codegen tests on platformName and platformStatic
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import kotlin.platform.*
|
||||
|
||||
@platformName("bar")
|
||||
fun foo() = "foo"
|
||||
|
||||
fun box(): String {
|
||||
val f = (::foo)()
|
||||
if (f != "foo") return "Fail: $f"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import kotlin.platform.*
|
||||
|
||||
fun <T> List<T>.foo() = "foo"
|
||||
|
||||
@platformName("fooInt")
|
||||
fun List<Int>.foo() = "fooInt"
|
||||
|
||||
fun box(): String {
|
||||
val strings = listOf("", "").foo()
|
||||
if (strings != "foo") return "Fail: $strings"
|
||||
|
||||
val ints = listOf(1, 2).foo()
|
||||
if (ints != "fooInt") return "Fail: $ints"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import kotlin.platform.*
|
||||
|
||||
// See:
|
||||
// http://kotlinlang.org/docs/reference/java-interop.html#handling-signature-clashes-with-platformname
|
||||
// https://youtrack.jetbrains.com/issue/KT-5524
|
||||
|
||||
val strs = listOf("abc", "def")
|
||||
val ints = listOf(1, 2, 3)
|
||||
|
||||
class C {
|
||||
// Instance methods
|
||||
|
||||
@platformName("instMethodStr")
|
||||
fun instMethod(list: List<String>): String = "instMethodStr"
|
||||
|
||||
@platformName("instMethodInt")
|
||||
fun instMethod(list: List<Int>): String = "instMethodInt"
|
||||
|
||||
// Properties
|
||||
|
||||
var rwProperty: Int
|
||||
@platformName("get_rwProperty")
|
||||
get() = 123
|
||||
@platformName("set_rwProperty")
|
||||
set(v) {}
|
||||
|
||||
var rwValue = 111
|
||||
|
||||
fun getRwProperty(): Int = rwValue
|
||||
|
||||
fun setRwProperty(v: Int) {
|
||||
rwValue = v
|
||||
}
|
||||
|
||||
// Extension methods
|
||||
|
||||
class Inner
|
||||
|
||||
@platformName("extMethodWithGenericParamStr")
|
||||
fun Inner.extMethodWithGenericParam(list: List<String>): String = "extMethodWithGenericParamStr"
|
||||
|
||||
@platformName("extMethodWithGenericParamInt")
|
||||
fun Inner.extMethodWithGenericParam(list: List<Int>): String = "extMethodWithGenericParamInt"
|
||||
|
||||
// This is already covered by extMethodWithGenericParam(), but might be relevant for a platform
|
||||
// with extension method code generation strategy different from Java 6.
|
||||
|
||||
@platformName("extMethodWithGenericReceiverStr")
|
||||
fun List<String>.extMethodWithGenericReceiver(): String = "extMethodWithGenericReceiverStr"
|
||||
|
||||
@platformName("extMethodWithGenericReceiverInt")
|
||||
fun List<Int>.extMethodWithGenericReceiver(): String = "extMethodWithGenericReceiverInt"
|
||||
|
||||
// Extension method vs instance method
|
||||
|
||||
@platformName("ambigMethod1")
|
||||
fun ambigMethod(str: String): String = "ambigMethod1"
|
||||
|
||||
@platformName("ambigMethod2")
|
||||
fun String.ambigMethod(): String = "ambigMethod2"
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
|
||||
// Instance methods:
|
||||
// method signatures with erased types SHOULD NOT clash
|
||||
|
||||
val test1 = c.instMethod(strs)
|
||||
if (test1 != "instMethodStr") return "Fail: c.instMethod(strs)==$test1"
|
||||
|
||||
val test2 = c.instMethod(ints)
|
||||
if (test2 != "instMethodInt") return "Fail: c.instMethod(ints)==$test2"
|
||||
|
||||
// Properties:
|
||||
// property accessors SHOULD NOT clash with class methods
|
||||
|
||||
val test3 = c.rwProperty
|
||||
if (test3 != 123) return "Fail: c.rwProperty==$test3"
|
||||
|
||||
val test3a = c.getRwProperty()
|
||||
if (test3a != 111) return "Fail: c.getRwProperty()==$test3a"
|
||||
|
||||
c.setRwProperty(444)
|
||||
val test3b = c.rwProperty
|
||||
if (test3b != 123) return "Fail: c.rwProperty==$test3b after c.setRwProperty(1234)"
|
||||
val test3c = c.getRwProperty()
|
||||
if (test3c != 444) return "Fail: c.getRwProperty()==$test3c after c.setRwProperty(1234)"
|
||||
|
||||
// Extension methods:
|
||||
// method signatures with erased types SHOULD NOT clash
|
||||
|
||||
val test4 = with(c) { C.Inner().extMethodWithGenericParam(strs) }
|
||||
if (test4 != "extMethodWithGenericParamStr") return "Fail: with(c) { C.Inner().extMethodWithGenericParam(strs) }==$test4"
|
||||
|
||||
val test5 = with(c) { C.Inner().extMethodWithGenericParam(ints) }
|
||||
if (test5 != "extMethodWithGenericParamInt") return "Fail: with(c) { C.Inner().extMethodWithGenericParam(ints) }==$test5"
|
||||
|
||||
val test6 = with(c) { strs.extMethodWithGenericReceiver() }
|
||||
if (test6 != "extMethodWithGenericReceiverStr") return "Fail: with(c) { strs.extMethodWithGenericReceiver() }==$test6"
|
||||
|
||||
val test7 = with(c) { ints.extMethodWithGenericReceiver() }
|
||||
if (test7 != "extMethodWithGenericReceiverInt") return "Fail: with(c) { ints.extMethodWithGenericReceiver() }==$test7"
|
||||
|
||||
// Extension method SHOULD NOT clash with instance method with the same Java signature.
|
||||
|
||||
val str = "abc"
|
||||
|
||||
val test8 = with(c) { ambigMethod(str) }
|
||||
if (test8 != "ambigMethod1") return "Fail: with(c) { ambigMethod(str) }==$test8"
|
||||
|
||||
val test9 = with(c) { str.ambigMethod() }
|
||||
if (test9 != "ambigMethod2") return "Fail: with(c) { str.ambigMethod() }==$test9"
|
||||
|
||||
// Everything is fine.
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import kotlin.platform.*
|
||||
|
||||
@platformName("bar")
|
||||
fun foo() = "foo"
|
||||
|
||||
fun box(): String {
|
||||
val f = foo()
|
||||
if (f != "foo") return "Fail: $f"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
@file:JvmName("Test")
|
||||
@file:JvmMultifileClass
|
||||
package test
|
||||
|
||||
fun foo(): String = bar()
|
||||
fun bar(): String = qux()
|
||||
fun qux(): String = "OK"
|
||||
|
||||
fun box(): String = foo()
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
@file:JvmName("Test")
|
||||
@file:JvmMultifileClass
|
||||
package test
|
||||
|
||||
fun foo(): String = bar()
|
||||
fun bar(): String {
|
||||
class Local(val x: String)
|
||||
return Local("OK").x
|
||||
}
|
||||
|
||||
fun box(): String = foo()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
@file:JvmName("Test")
|
||||
@file:JvmMultifileClass
|
||||
package test
|
||||
|
||||
fun foo(): String = bar()
|
||||
fun bar(): String {
|
||||
open class LocalGeneric<T>(val x: T)
|
||||
class Derived(x: String) : LocalGeneric<String>(x)
|
||||
fun <T> LocalGeneric<T>.extFun() = this
|
||||
fun <T> localFun(x: LocalGeneric<T>) = x
|
||||
class Local3 {
|
||||
fun <T> method(x: LocalGeneric<T>) = x.x
|
||||
}
|
||||
return Local3().method(localFun(Derived("OK")).extFun())
|
||||
}
|
||||
|
||||
fun box(): String = foo()
|
||||
@@ -0,0 +1,14 @@
|
||||
import kotlin.platform.*
|
||||
|
||||
var v: Int = 1
|
||||
@platformName("vget")
|
||||
get
|
||||
@platformName("vset")
|
||||
set
|
||||
|
||||
fun box(): String {
|
||||
v += 1
|
||||
if (v != 2) return "Fail: $v"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@file:JvmName("Util")
|
||||
package test
|
||||
|
||||
fun foo(): String = bar()
|
||||
fun bar(): String = qux()
|
||||
fun qux(): String = "OK"
|
||||
|
||||
fun box(): String = foo()
|
||||
Reference in New Issue
Block a user