Minor. Add more tests
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class S<T: String>(val string: T)
|
||||
|
||||
fun foo(s: S<String>): String {
|
||||
val anon = object {
|
||||
fun bar() = s.string
|
||||
}
|
||||
return anon.bar()
|
||||
}
|
||||
|
||||
fun box() = foo(S("OK"))
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Id<T: String>(val id: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Name<T: String>(val name: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Password<T: String>(val password: T)
|
||||
|
||||
fun Id<String>.test() {
|
||||
if (id != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun Id<String>?.test() {
|
||||
if (this != null) throw AssertionError()
|
||||
}
|
||||
|
||||
fun Name<String>.test() {
|
||||
if (name != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun test(password: Password<String>) {
|
||||
if (password.password != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
class Outer {
|
||||
fun Id<String>.testExn() {
|
||||
if (id != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun Name<String>.testExn() {
|
||||
if (name != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun testExn(password: Password<String>) {
|
||||
if (password.password != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun testExns() {
|
||||
Id("OK").testExn()
|
||||
Name("OK").testExn()
|
||||
testExn(Password("OK"))
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Id("OK").test()
|
||||
null.test()
|
||||
Name("OK").test()
|
||||
test(Password("OK"))
|
||||
|
||||
Outer().testExns()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Id<T: String>(val id: T)
|
||||
|
||||
fun test(id: Id<String>) {
|
||||
if (id.id != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun test(id: Id<String>?) {
|
||||
if (id != null) throw AssertionError()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(Id("OK"))
|
||||
test(null)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class S1<T: String>(val s1: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class S2<T: String>(val s2: T)
|
||||
|
||||
object X1
|
||||
object X2
|
||||
|
||||
fun <T> test(s1: S1<String>, x: T) {
|
||||
if (s1.s1 != "OK" && x != X1) throw AssertionError()
|
||||
}
|
||||
|
||||
fun <T> test(s2: S2<String>, x: T) {
|
||||
if (s2.s2 != "OK" && x != X2) throw AssertionError()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(S1("OK"), X1)
|
||||
test(S2("OK"), X2)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.reflect.jvm.javaMethod
|
||||
import kotlin.test.*
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class InlineClass1<T: String>(val s: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class InlineClass2<T: Number>(val n: T)
|
||||
|
||||
fun <T : InlineClass1<String>, U : InlineClass2<Number>> foo(t: T, u: U) {}
|
||||
|
||||
fun box(): String {
|
||||
val fooRef: (InlineClass1<String>, InlineClass2<Number>) -> Unit = ::foo
|
||||
val fooMethod = (fooRef as KFunction<*>).javaMethod!!
|
||||
|
||||
assertEquals("[T, U]", fooMethod.genericParameterTypes.asList().toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class S<T: String>(val string: T)
|
||||
|
||||
fun foo(s: S<String>): String {
|
||||
class Local {
|
||||
fun bar() = s.string
|
||||
}
|
||||
return Local().bar()
|
||||
}
|
||||
|
||||
fun box() = foo(S("OK"))
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Id<T: String>(val id: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Name<T: String>(val name: T)
|
||||
|
||||
interface IA {
|
||||
fun fromInterface(id: Id<String>)
|
||||
fun fromInterface(name: Name<String>)
|
||||
|
||||
fun fromBoth(id: Id<String>)
|
||||
fun fromBoth(name: Name<String>)
|
||||
|
||||
fun withDefaultImpl(id: Id<String>) {
|
||||
if (id.id != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun withDefaultImpl(name: Name<String>) {
|
||||
if (name.name != "OK") throw AssertionError()
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Base {
|
||||
abstract fun fromClass(id: Id<String>)
|
||||
abstract fun fromClass(name: Name<String>)
|
||||
|
||||
abstract fun fromBoth(id: Id<String>)
|
||||
abstract fun fromBoth(name: Name<String>)
|
||||
}
|
||||
|
||||
|
||||
class C : Base(), IA {
|
||||
override fun fromInterface(id: Id<String>) {
|
||||
if (id.id != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
override fun fromInterface(name: Name<String>) {
|
||||
if (name.name != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
override fun fromClass(id: Id<String>) {
|
||||
if (id.id != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
override fun fromClass(name: Name<String>) {
|
||||
if (name.name != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
override fun fromBoth(id: Id<String>) {
|
||||
if (id.id != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
override fun fromBoth(name: Name<String>) {
|
||||
if (name.name != "OK") throw AssertionError()
|
||||
}
|
||||
}
|
||||
|
||||
fun testIA(a: IA) {
|
||||
a.fromInterface(Id("OK"))
|
||||
a.fromInterface(Name("OK"))
|
||||
|
||||
a.fromBoth(Id("OK"))
|
||||
a.fromBoth(Name("OK"))
|
||||
|
||||
a.withDefaultImpl(Id("OK"))
|
||||
a.withDefaultImpl(Name("OK"))
|
||||
}
|
||||
|
||||
fun testBase(b: Base) {
|
||||
b.fromClass(Id("OK"))
|
||||
b.fromClass(Name("OK"))
|
||||
|
||||
b.fromBoth(Id("OK"))
|
||||
b.fromBoth(Name("OK"))
|
||||
}
|
||||
|
||||
fun testC(c: C) {
|
||||
c.withDefaultImpl(Id("OK"))
|
||||
c.withDefaultImpl(Name("OK"))
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testIA(C())
|
||||
testBase(C())
|
||||
testC(C())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Id<T: String>(val id: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Name<T: String>(val name: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Password<T: String>(val password: T)
|
||||
|
||||
fun test(id: Id<String>) {
|
||||
if (id.id != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun test(name: Name<String>) {
|
||||
if (name.name != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun test(password: Password<String>) {
|
||||
if (password.password != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(Id("OK"))
|
||||
test(Name("OK"))
|
||||
test(Password("OK"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// IGNORE_BACKEND: JS, JS_IR, WASM
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// FULL_JDK
|
||||
// WITH_STDLIB
|
||||
// WASM_MUTE_REASON: IGNORED_IN_JS
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Id<T: String>(val id: T)
|
||||
|
||||
fun throws() {
|
||||
throw RuntimeException()
|
||||
}
|
||||
|
||||
fun test(id: Id<String>) {
|
||||
throws()
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
test(Id("id"))
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val stackTrace = try {
|
||||
foo()
|
||||
throw AssertionError()
|
||||
} catch (e: RuntimeException) {
|
||||
e.stackTrace
|
||||
}
|
||||
|
||||
for (entry in stackTrace) {
|
||||
if (entry.methodName.startsWith("test")) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
throw AssertionError(stackTrace.asList().toString())
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Id<T: String>(val id: T)
|
||||
|
||||
fun test(id: Id<String>, str: String) {
|
||||
if (id.id != "OK" && str != "1") throw AssertionError()
|
||||
}
|
||||
|
||||
fun test(str: String, id: Id<String>) {
|
||||
if (id.id != "OK" && str != "2") throw AssertionError()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(Id("OK"), "1")
|
||||
test("2", Id("OK"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
abstract class GenericBase<T> {
|
||||
abstract fun foo(x: T): T
|
||||
}
|
||||
|
||||
interface IFoo {
|
||||
fun foo(x: String): String
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Str<T: String>(val str: T)
|
||||
|
||||
class Derived : GenericBase<Str<String>>(), IFoo {
|
||||
override fun foo(x: Str<String>): Str<String> = x
|
||||
override fun foo(x: String): String = x
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Derived().foo(Str("OK")).str != "OK") throw AssertionError()
|
||||
if (Derived().foo("OK") != "OK") throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
abstract class GenericBase<T> {
|
||||
abstract fun foo(x: T): T
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Str<T: String>(val str: T)
|
||||
|
||||
class Derived : GenericBase<Str<String>>() {
|
||||
override fun foo(x: Str<String>): Str<String> = x
|
||||
}
|
||||
|
||||
fun box() = Derived().foo(Str("OK")).str
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Str<T: String>(val string: T)
|
||||
|
||||
class C {
|
||||
var s = Str("")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = C()
|
||||
x.s = Str("OK")
|
||||
return x.s.string
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class S<T: String>(val string: T)
|
||||
|
||||
fun foo(s: S<String>) = s
|
||||
|
||||
fun box(): String {
|
||||
val fooRef = ::foo
|
||||
|
||||
assertEquals("abc", fooRef.invoke(S("abc")).string)
|
||||
assertEquals("foo", fooRef.name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class S<T: String>(val string: T)
|
||||
|
||||
fun test(s: S<String>) {
|
||||
class Local
|
||||
|
||||
val localKClass = Local::class
|
||||
val localJClass = localKClass.java
|
||||
|
||||
val kName = localKClass.simpleName
|
||||
// See https://youtrack.jetbrains.com/issue/KT-29413
|
||||
// assertEquals("Local", kName)
|
||||
if (kName != "Local" && kName != "test\$Local") throw AssertionError("Fail KClass: $kName")
|
||||
|
||||
assertTrue { localJClass.isLocalClass }
|
||||
|
||||
val jName = localJClass.simpleName
|
||||
if (jName != "Local" && jName != "test\$Local") throw AssertionError("Fail java.lang.Class: $jName")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(S(""))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class S<T: String>(val string: T)
|
||||
|
||||
var prop = S("")
|
||||
|
||||
fun box(): String {
|
||||
val propRef = ::prop
|
||||
|
||||
assertEquals(S(""), propRef.get())
|
||||
|
||||
propRef.set(S("abc"))
|
||||
assertEquals(S("abc"), propRef.get())
|
||||
|
||||
assertEquals("prop", propRef.name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class S<T: String>(val string: T)
|
||||
|
||||
class Outer {
|
||||
private fun foo(s: S<String>) = s.string
|
||||
|
||||
inner class Inner(val string: String) {
|
||||
fun bar() = foo(S(string))
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = Outer().Inner("OK").bar()
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class S<T: String>(val string: T)
|
||||
|
||||
class Outer {
|
||||
private var pr = S("")
|
||||
|
||||
inner class Inner() {
|
||||
fun updateOuter(string: String): String {
|
||||
pr = S(string)
|
||||
return pr.string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
Outer().Inner().updateOuter("OK")
|
||||
Reference in New Issue
Block a user