Minor. Add tests
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Long>(private val r: T) {
|
||||
fun test() = ok()
|
||||
|
||||
companion object {
|
||||
private fun ok() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = ok()
|
||||
|
||||
companion object {
|
||||
private fun ok() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Composed<T: String>(val s: T) {
|
||||
private constructor(s1: String, s2: String) : this((s1 + s2) as T)
|
||||
|
||||
companion object {
|
||||
fun p1(s: String) = Composed<String>("O", s)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Composed.p1("K").s
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Composed<T: String>(val s: T) {
|
||||
|
||||
constructor(s: String, x: Int) : this(s.subSequence(0, x).toString() as T)
|
||||
|
||||
private constructor(s1: String, s2: String) : this((s1 + s2) as T, 2)
|
||||
|
||||
fun p1(s2: String) =
|
||||
{ Composed<String>(s, s2) }
|
||||
}
|
||||
|
||||
fun box() = Composed<String>("O").p1("K1234")().s
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Long>(private val r: T) {
|
||||
private fun ok() = "OK"
|
||||
|
||||
companion object {
|
||||
fun test(r: R<Long>) = r.ok()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = R.test(R(0))
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
private fun ok() = "OK"
|
||||
|
||||
companion object {
|
||||
fun test(r: R<Int>) = r.ok()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = R.test(R(0))
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Long>(private val r: T) {
|
||||
fun test() = run { ok() }
|
||||
|
||||
private fun ok() = "OK"
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = run { ok() }
|
||||
|
||||
private fun ok() = "OK"
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Long>(private val r: T) {
|
||||
fun test() = { ok() }()
|
||||
|
||||
private fun ok() = "OK"
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
fun <T> eval(fn: () -> T) = fn()
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = eval { ok() }
|
||||
|
||||
private fun ok() = "OK"
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = ok()
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
private fun ok() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Long>(private val r: T) {
|
||||
fun test() = { ok() }()
|
||||
|
||||
fun ok() = "OK"
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = { ok() }()
|
||||
|
||||
fun ok() = "OK"
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = object {
|
||||
override fun toString() = ok()
|
||||
}.toString()
|
||||
|
||||
fun ok() = "OK"
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
inline fun runInline(fn: () -> String) = fn()
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = runInline { "OK" }
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Direction<T: Int>(private val direction: T) {
|
||||
fun dx() = dx[direction]
|
||||
fun dy() = dy[direction]
|
||||
|
||||
companion object {
|
||||
private val dx = intArrayOf(0, 1, 0, -1)
|
||||
private val dy = intArrayOf(-1, 0, 1, 0)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val dirs = arrayOf(Direction(0), Direction(1), Direction(2), Direction(3))
|
||||
val expectedDx = intArrayOf(0, 1, 0, -1)
|
||||
val expectedDy = intArrayOf(-1, 0, 1, 0)
|
||||
for (i in 0 .. 3) {
|
||||
if (dirs[i].dx() != expectedDx[i]) throw AssertionError()
|
||||
if (dirs[i].dy() != expectedDy[i]) throw AssertionError()
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class A<T: String>(val b: T) {
|
||||
override fun toString(): String =
|
||||
buildString { append(b) }
|
||||
}
|
||||
|
||||
fun box() = A("OK").toString()
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Test<T: Int>(val x: T) {
|
||||
private companion object {
|
||||
private const val CONSTANT = "OK"
|
||||
}
|
||||
|
||||
fun crash() = getInlineConstant()
|
||||
|
||||
private inline fun getInlineConstant(): String {
|
||||
return CONSTANT
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Test(1).crash()
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
fun <T> eval(fn: () -> T) = fn()
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = eval { "OK" }
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() =
|
||||
object {
|
||||
override fun toString() = "OK"
|
||||
}.toString()
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = pf()
|
||||
|
||||
companion object {
|
||||
private fun pf() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class R<T: Int>(private val r: T) {
|
||||
fun test() = pv
|
||||
|
||||
companion object {
|
||||
private val pv = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
Reference in New Issue
Block a user