Minor. Add more tests

This commit is contained in:
Ilmir Usmanov
2021-12-28 11:52:26 +01:00
parent c8817893d4
commit cece7120df
274 changed files with 20551 additions and 25 deletions
@@ -0,0 +1,48 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
fun <T: Any> underlying(a: IC<T>): T = bar(a) {
it.value
}
fun <T: Any> extension(a: IC<T>): T = bar(a) {
it.extensionValue()
}
fun <T: Any> dispatch(a: IC<T>): T = bar(a) {
it.dispatchValue()
}
fun <T: Any> normal(a: IC<T>): T = bar(a) {
normalValue(it)
}
fun <T: Any> IC<T>.extensionValue(): T = value
fun <T: Any> normalValue(ic: IC<T>): T = ic.value
fun <T, R> bar(value: T, f: (T) -> R): R {
return f(value)
}
OPTIONAL_JVM_INLINE_ANNOTATION
value class IC<T: Any>(val value: T) {
fun dispatchValue(): T = value
}
fun box(): String {
var res = underlying<Int>(IC(40)) + 2
if (res != 42) return "FAIL 1: $res"
res = extension<Int>(IC(40)) + 3
if (res != 43) return "FAIL 2: $res"
res = dispatch<Int>(IC(40)) + 4
if (res != 44) return "FAIL 3: $res"
res = normal<Int>(IC(40)) + 5
if (res != 45) return "FAIL 4: $res"
return "OK"
}
@@ -0,0 +1,48 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
fun <T> underlying(a: IC<T>): T = bar(a) {
it.value
}
fun <T> extension(a: IC<T>): T = bar(a) {
it.extensionValue()
}
fun <T> dispatch(a: IC<T>): T = bar(a) {
it.dispatchValue()
}
fun <T> normal(a: IC<T>): T = bar(a) {
normalValue(it)
}
fun <T, R> bar(value: T, f: (T) -> R): R {
return f(value)
}
fun <T> IC<T>.extensionValue(): T = value
fun <T> normalValue(ic: IC<T>): T = ic.value
OPTIONAL_JVM_INLINE_ANNOTATION
value class IC<T>(val value: T) {
fun dispatchValue(): T = value
}
fun box(): String {
var res = underlying<Int>(IC(40)) + 2
if (res != 42) "FAIL 1 $res"
res = extension<Int>(IC(40)) + 3
if (res != 43) return "FAIL 2: $res"
res = dispatch<Int>(IC(40)) + 4
if (res != 44) return "FAIL 3: $res"
res = normal<Int>(IC(40)) + 5
if (res != 45) return "FAIL 4: $res"
return "OK"
}
@@ -0,0 +1,52 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
fun <T> underlying(a: IC<FooHolder>): T = bar(a) {
it.value.value as T
}
fun <T> extension(a: IC<FooHolder>): T = bar(a) {
it.extensionValue()
}
fun <T> dispatch(a: IC<FooHolder>): T = bar(a) {
it.dispatchValue()
}
fun <T> normal(a: IC<FooHolder>): T = bar(a) {
normalValue(it)
}
fun <T> IC<FooHolder>.extensionValue(): T = value.value as T
fun <T> normalValue(ic: IC<FooHolder>): T = ic.value.value as T
fun <T, R> bar(value: T, f: (T) -> R): R {
return f(value)
}
interface Foo
class FooHolder(val value: Any): Foo
OPTIONAL_JVM_INLINE_ANNOTATION
value class IC<T: FooHolder>(val value: T): Foo {
fun <T> dispatchValue(): T = value.value as T
}
fun box(): String {
var res = underlying<Int>(IC(FooHolder(40))) + 2
if (res != 42) return "FAIL 1: $res"
res = extension<Int>(IC(FooHolder(40))) + 3
if (res != 43) return "FAIL 2: $res"
res = dispatch<Int>(IC(FooHolder(40))) + 4
if (res != 44) return "FAIL 3: $res"
res = normal<Int>(IC(FooHolder(40))) + 5
if (res != 45) return "FAIL 4: $res"
return "OK"
}
@@ -0,0 +1,52 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
fun <T> underlying(a: IC<FooHolder>): T = bar(a) {
it.value.value as T
}
fun <T> extension(a: IC<FooHolder>): T = bar(a) {
it.extensionValue()
}
fun <T> dispatch(a: IC<FooHolder>): T = bar(a) {
it.dispatchValue()
}
fun <T> normal(a: IC<FooHolder>): T = bar(a) {
normalValue(it)
}
fun <T> IC<FooHolder>.extensionValue(): T = value.value as T
fun <T> normalValue(ic: IC<FooHolder>): T = ic.value.value as T
fun <T, R> bar(value: T, f: (T) -> R): R {
return f(value)
}
interface Foo
class FooHolder(val value: Any): Foo
OPTIONAL_JVM_INLINE_ANNOTATION
value class IC<T: Foo>(val value: T): Foo {
fun <T> dispatchValue(): T = (value as FooHolder).value as T
}
fun box(): String {
var res = underlying<Int>(IC(FooHolder(40))) + 2
if (res != 42) return "FAIL 1: $res"
res = extension<Int>(IC(FooHolder(40))) + 3
if (res != 43) return "FAIL 2: $res"
res = dispatch<Int>(IC(FooHolder(40))) + 4
if (res != 44) return "FAIL 3: $res"
res = normal<Int>(IC(FooHolder(40))) + 5
if (res != 45) return "FAIL 4: $res"
return "OK"
}
@@ -0,0 +1,48 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
fun <T: Int> underlying(a: IC<T>): T = bar(a) {
it.value
}
fun <T: Int> extension(a: IC<T>): T = bar(a) {
it.extensionValue()
}
fun <T: Int> dispatch(a: IC<T>): T = bar(a) {
it.dispatchValue()
}
fun <T: Int> normal(a: IC<T>): T = bar(a) {
normalValue(it)
}
fun <T, R> bar(value: T, f: (T) -> R): R {
return f(value)
}
fun <T: Int> IC<T>.extensionValue(): T = value
fun <T: Int> normalValue(ic: IC<T>): T = ic.value
OPTIONAL_JVM_INLINE_ANNOTATION
value class IC<T: Int>(val value: T) {
fun dispatchValue(): T = value
}
fun box(): String {
var res = underlying<Int>(IC(40)) + 2
if (res != 42) "FAIL 1: $res"
res = extension<Int>(IC(40)) + 3
if (res != 43) "FAIL 2: $res"
res = dispatch<Int>(IC(40)) + 4
if (res != 44) "FAIL 3: $res"
res = normal<Int>(IC(40)) + 5
if (res != 45) return "FAIL 4: $res"
return "OK"
}
@@ -0,0 +1,18 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
OPTIONAL_JVM_INLINE_ANNOTATION
value class IC<T: Any>(val value: T)
fun <T: Any> foo(a: Result<T>, ic: IC<T>): Pair<T, Any> = bar(a, ic) { a, ic ->
a.getOrThrow() to ic.value
}
fun <T1, T2, R> bar(t1: T1, t2: T2, f: (T1, T2) -> R): R {
return f(t1, t2)
}
fun Pair<Any, Any>.join(): String = "$first$second"
fun box(): String = foo<Any>(Result.success("O"), IC("K")).join()
@@ -0,0 +1,48 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
fun <T: String> underlying(a: IC<T>): T = bar(a) {
it.value
}
fun <T: String> extension(a: IC<T>): T = bar(a) {
it.extensionValue()
}
fun <T: String> dispatch(a: IC<T>): T = bar(a) {
it.dispatchValue()
}
fun <T: String> normal(a: IC<T>): T = bar(a) {
normalValue(it)
}
fun <T, R> bar(value: T, f: (T) -> R): R {
return f(value)
}
fun <T: String> IC<T>.extensionValue(): T = value
fun <T: String> normalValue(ic: IC<T>): T = ic.value
OPTIONAL_JVM_INLINE_ANNOTATION
value class IC<T: String>(val value: T) {
fun dispatchValue(): T = value
}
fun box(): String {
var res = underlying<String>(IC("O")) + "K"
if (res != "OK") return "FAIL 1: $res"
res = extension<String>(IC("O")) + "K"
if (res != "OK") return "FAIL 2: $res"
res = dispatch<String>(IC("O")) + "K"
if (res != "OK") return "FAIL 3: $res"
res = normal<String>(IC("O")) + "K"
if (res != "OK") return "FAIL 3: $res"
return "OK"
}