Fix mapping of nullable generic underlying types of inline classes
#KT-32162 Fixed
This commit is contained in:
Vendored
+71
@@ -0,0 +1,71 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcInt<T: Int>(val i: T) {
|
||||
fun simple(): String = i.toString()
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcLong<T: Long>(val l: T) {
|
||||
fun simple(): String = l.toString()
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcAny<T: Any>(val a: T?) {
|
||||
fun simple(): String = a?.toString() ?: "null"
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcOverIc<T: IcLong<Long>>(val o: T) {
|
||||
fun simple(): String = o.toString()
|
||||
}
|
||||
|
||||
fun testUnboxed(i: IcInt<Int>, l: IcLong<Long>, a: IcAny<Int>, o: IcOverIc<IcLong<Long>>): String =
|
||||
foo(i::simple) + foo(l::simple) + foo(a::simple) + foo(o::simple)
|
||||
|
||||
fun testBoxed(i: IcInt<Int>?, l: IcLong<Long>?, a: IcAny<Int>?, o: IcOverIc<IcLong<Long>>?): String =
|
||||
foo(i!!::simple) + foo(l!!::simple) + foo(a!!::simple) + foo(o!!::simple)
|
||||
|
||||
fun testLocalVars(): String {
|
||||
val i = IcInt(0)
|
||||
val l = IcLong(1L)
|
||||
val a = IcAny(2)
|
||||
val o = IcOverIc(IcLong(3))
|
||||
|
||||
return foo(i::simple) + foo(l::simple) + foo(a::simple) + foo(o::simple)
|
||||
}
|
||||
|
||||
val ip = IcInt(1)
|
||||
val lp = IcLong(2L)
|
||||
val ap = IcAny(3)
|
||||
val op = IcOverIc(IcLong(4))
|
||||
|
||||
fun testGlobalProperties(): String =
|
||||
foo(ip::simple) + foo(lp::simple) + foo(ap::simple) + foo(op::simple)
|
||||
|
||||
fun testCapturedVars(): String {
|
||||
return IcInt(2).let { foo(it::simple) } +
|
||||
IcLong(3).let { foo(it::simple) } +
|
||||
IcAny(4).let { foo(it::simple) } +
|
||||
IcOverIc(IcLong(5)).let { foo(it::simple) }
|
||||
}
|
||||
|
||||
inline fun foo(init: () -> String): String = init()
|
||||
|
||||
fun box(): String {
|
||||
val i = IcInt(3)
|
||||
val l = IcLong(4)
|
||||
val a = IcAny(5)
|
||||
val o = IcOverIc(IcLong(6))
|
||||
|
||||
if (testUnboxed(i, l, a, o) != "345IcLong(l=6)") return "Fail 1 ${testUnboxed(i, l, a, o)}"
|
||||
if (testBoxed(i, l, a, o) != "345IcLong(l=6)") return "Fail 2"
|
||||
if (testLocalVars() != "012IcLong(l=3)") return "Fail 3"
|
||||
if (testGlobalProperties() != "123IcLong(l=4)") return "Fail 4"
|
||||
if (testCapturedVars() != "234IcLong(l=5)") return "Fail 5 ${testCapturedVars()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
abstract class C<T> {
|
||||
fun foo(v: T?, x: (T) -> Any?) = v?.let { x(it) }
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class V<T: Any>(val value: T?)
|
||||
|
||||
class D : C<V<String>>()
|
||||
|
||||
fun box() = D().foo(V("OK")) { it.value } as String
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
class BoxT<T: Any>(val boxed: T?)
|
||||
class BoxAny(val boxed: Any?)
|
||||
class BoxFoo(val boxed: IFoo?)
|
||||
|
||||
interface IFoo
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Str<T: String>(val value: T) : IFoo
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Str2<T: Str<String>>(val value: T): IFoo
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class StrArr(val value: Array<String>): IFoo
|
||||
|
||||
fun boxToTypeParameter(x: Str<String>?) = BoxT(x)
|
||||
fun boxToNullableAny(x: Str<String>?) = BoxAny(x)
|
||||
fun boxToNullableInterface(x: Str<String>?) = BoxFoo(x)
|
||||
|
||||
fun box2ToTypeParameter(x: Str2<Str<String>>?) = BoxT(x)
|
||||
fun box2ToNullableAny(x: Str2<Str<String>>?) = BoxAny(x)
|
||||
fun box2ToNullableInterface(x: Str2<Str<String>>?) = BoxFoo(x)
|
||||
|
||||
fun boxArrToTypeParameter(x: StrArr?) = BoxT(x)
|
||||
fun boxArrToNullableAny(x: StrArr?) = BoxAny(x)
|
||||
fun boxArrToNullableInterface(x: StrArr?) = BoxFoo(x)
|
||||
|
||||
fun box(): String {
|
||||
if (boxToNullableAny(null).boxed != null) throw AssertionError()
|
||||
if (boxToTypeParameter(null).boxed != null) throw AssertionError()
|
||||
if (boxToNullableInterface(null).boxed != null) throw AssertionError()
|
||||
|
||||
if (box2ToNullableAny(null).boxed != null) throw AssertionError()
|
||||
if (box2ToTypeParameter(null).boxed != null) throw AssertionError()
|
||||
if (box2ToNullableInterface(null).boxed != null) throw AssertionError()
|
||||
|
||||
if (boxArrToNullableAny(null).boxed != null) throw AssertionError()
|
||||
if (boxArrToTypeParameter(null).boxed != null) throw AssertionError()
|
||||
if (boxArrToNullableInterface(null).boxed != null) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
class BoxT<T: Any>(val boxed: T?)
|
||||
class BoxAny(val boxed: Any?)
|
||||
class BoxFoo(val boxed: IFoo?)
|
||||
|
||||
interface IFoo
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class I32<T: Int>(val value: T): IFoo
|
||||
|
||||
fun boxToTypeParameter(x: I32<Int>?) = BoxT(x)
|
||||
fun boxToNullableAny(x: I32<Int>?) = BoxAny(x)
|
||||
fun boxToNullableInterface(x: I32<Int>?) = BoxFoo(x)
|
||||
|
||||
fun box(): String {
|
||||
if (boxToNullableAny(null).boxed != null) throw AssertionError()
|
||||
if (boxToTypeParameter(null).boxed != null) throw AssertionError()
|
||||
if (boxToNullableInterface(null).boxed != null) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Result<T: Any>(val a: T?)
|
||||
|
||||
fun box(): String {
|
||||
val a = Result<Int>(1) // valueOf
|
||||
val b = Result<String>("sample")
|
||||
val c = Result<Result<Int>>(a)
|
||||
val d = Result<Result<Int>>(Result<Int>(1)) // valueOf
|
||||
|
||||
if (a.a !is Int) throw AssertionError()
|
||||
|
||||
if (b.a !is String) throw AssertionError()
|
||||
|
||||
if (c.a !is Result<*>) throw AssertionError()
|
||||
val ca = c.a as Result<*>
|
||||
if (ca.a !is Int) throw AssertionError()
|
||||
|
||||
if (d.a !is Result<*>) throw AssertionError()
|
||||
val da = d.a as Result<*>
|
||||
if (da.a !is Int) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: Any>(val x: T?)
|
||||
|
||||
fun useX(x: X<String>): String = x.x!!
|
||||
|
||||
fun <T> call(fn: () -> T) = fn()
|
||||
|
||||
fun box() = useX(call { X("OK") })
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: Any>(val x: T?)
|
||||
|
||||
fun useX(x: X<String>): String = if (x.x == null) "OK" else "fail: $x"
|
||||
|
||||
fun <T> call(fn: () -> T) = fn()
|
||||
|
||||
fun box() = useX(call { X(null) })
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: Int>(val x: T?)
|
||||
|
||||
fun useX(x: X<Int>): String = if (x.x == 42) "OK" else "fail: $x"
|
||||
|
||||
fun <T> call(fn: () -> T) = fn()
|
||||
|
||||
fun box() = useX(call { X(42) })
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: Int>(val x: T?)
|
||||
|
||||
fun useX(x: X<Int>): String = if (x.x == null) "OK" else "fail: $x"
|
||||
|
||||
fun <T> call(fn: () -> T) = fn()
|
||||
|
||||
fun box() = useX(call { X(null) })
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: String>(val x: T?)
|
||||
|
||||
fun useX(x: X<String>): String = x.x ?: "fail: $x"
|
||||
|
||||
fun <T> call(fn: () -> T) = fn()
|
||||
|
||||
fun box() = useX(call { X("OK") })
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: String>(val x: T?)
|
||||
|
||||
fun useX(x: X<String>): String = if (x.x == null) "OK" else "fail: $x"
|
||||
|
||||
fun <T> call(fn: () -> T) = fn()
|
||||
|
||||
fun box() = useX(call { X(null) })
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: Any>(val x: T?)
|
||||
|
||||
interface IBar {
|
||||
fun bar(): Any
|
||||
}
|
||||
|
||||
interface IFoo : IBar {
|
||||
fun foo(): Any
|
||||
override fun bar(): X<String>
|
||||
}
|
||||
|
||||
class TestX : IFoo {
|
||||
override fun foo(): X<String> = X("O")
|
||||
override fun bar(): X<String> = X("K")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t: IFoo = TestX()
|
||||
val tFoo = t.foo()
|
||||
if (tFoo !is X<*>) {
|
||||
throw AssertionError("X expected: $tFoo")
|
||||
}
|
||||
|
||||
val t2: IBar = TestX()
|
||||
val tBar = t.bar()
|
||||
if (tBar !is X<*>) {
|
||||
throw AssertionError("X expected: $tBar")
|
||||
}
|
||||
|
||||
return (t.foo() as X<String>).x!!.toString() + (t2.bar() as X<String>).x!!.toString()
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class ResultOrClosed<T: Any>(val x: T?)
|
||||
|
||||
interface A<T> {
|
||||
fun foo(): T
|
||||
}
|
||||
|
||||
class B : A<ResultOrClosed<String>> {
|
||||
override fun foo(): ResultOrClosed<String> = ResultOrClosed("OK")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val foo: Any = (B() as A<ResultOrClosed<String>>).foo()
|
||||
if (foo !is ResultOrClosed<*>) throw AssertionError("foo: $foo")
|
||||
return foo.x.toString()
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: Any>(val x: T?)
|
||||
|
||||
interface IFoo<out T : X<String>?> {
|
||||
fun foo(): T
|
||||
}
|
||||
|
||||
class Test : IFoo<X<String>> {
|
||||
override fun foo(): X<String> = X("OK")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t1: IFoo<X<String>> = Test()
|
||||
val x1 = t1.foo()
|
||||
if (x1 != X("OK")) throw AssertionError("x1: $x1")
|
||||
|
||||
val t2 = Test()
|
||||
val x2 = t2.foo()
|
||||
if (x2 != X("OK")) throw AssertionError("x2: $x2")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// WITH_STDLIB
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: Any>(val x: T?)
|
||||
|
||||
interface IFoo<out T : X<String>?> {
|
||||
fun foo(): T
|
||||
}
|
||||
|
||||
class Test : IFoo<X<String>> {
|
||||
override fun foo(): X<String> = X(null)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t1: IFoo<X<String>?> = Test()
|
||||
val x1 = t1.foo()
|
||||
if (x1 != X(null)) throw AssertionError("x1: $x1")
|
||||
|
||||
val t2 = Test()
|
||||
val x2 = t2.foo()
|
||||
if (x2 != X(null)) throw AssertionError("x2: $x2")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: Any>(val x: T?)
|
||||
|
||||
interface IFoo {
|
||||
fun foo(): X<String>?
|
||||
}
|
||||
|
||||
class Test : IFoo {
|
||||
override fun foo(): X<String>? = X("OK")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t1: IFoo = Test()
|
||||
val x1 = t1.foo()
|
||||
if (x1 != X("OK")) throw AssertionError("x1: $x1")
|
||||
|
||||
val t2 = Test()
|
||||
val x2 = t2.foo()
|
||||
if (x2 != X("OK")) throw AssertionError("x2: $x2")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class X<T: Any>(val x: T?)
|
||||
|
||||
interface IFoo {
|
||||
fun foo(): X<String>?
|
||||
}
|
||||
|
||||
class Test : IFoo {
|
||||
override fun foo(): X<String>? = X(null)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t1: IFoo = Test()
|
||||
val x1 = t1.foo()
|
||||
if (x1 != X(null)) throw AssertionError("x1: $x1")
|
||||
|
||||
val t2 = Test()
|
||||
val x2 = t2.foo()
|
||||
if (x2 != X(null)) throw AssertionError("x2: $x2")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Result<T: Any>(val a: T?) {
|
||||
fun getOrThrow(): T? = a
|
||||
}
|
||||
|
||||
abstract class ResultReceiver<T: Any> {
|
||||
abstract fun receive(result: Result<T>)
|
||||
}
|
||||
|
||||
fun <T: Any> ResultReceiver(f: (Result<T>) -> Unit): ResultReceiver<T> =
|
||||
object : ResultReceiver<T>() {
|
||||
override fun receive(result: Result<T>) {
|
||||
f(result)
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
var invoked = false
|
||||
val receiver = ResultReceiver<Int> { result ->
|
||||
val intResult = result.getOrThrow()
|
||||
invoked = true
|
||||
}
|
||||
|
||||
receiver.receive(Result(42))
|
||||
if (!invoked) {
|
||||
throw RuntimeException("Fail")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test()
|
||||
return "OK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Value<T: Any>(val value: T?)
|
||||
|
||||
object Foo {
|
||||
fun foo(value: Value<String>) {
|
||||
res = value.value
|
||||
}
|
||||
|
||||
fun bar(value: Value<String>?) {
|
||||
res = value?.value
|
||||
}
|
||||
}
|
||||
|
||||
var res: String? = "FAIL"
|
||||
|
||||
fun box(): String {
|
||||
Value<String>("OK").let(Foo::foo)
|
||||
if (res != "OK") return "FAIL 1: $res"
|
||||
res = "FAIL 2"
|
||||
|
||||
Value<String>("OK").let(Foo::bar)
|
||||
if (res != "OK") return "FAIL 3: $res"
|
||||
res = "FAIL 4"
|
||||
|
||||
null.let(Foo::bar)
|
||||
if (res != null) return "FAIL 5: $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// CHECK_BYTECODE_LISTING
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Value<T: Int>(val value: T?)
|
||||
|
||||
object Foo {
|
||||
fun foo(value: Value<Int>) {
|
||||
res = value.value
|
||||
}
|
||||
|
||||
fun bar(value: Value<Int>?) {
|
||||
res = value?.value
|
||||
}
|
||||
}
|
||||
|
||||
var res: Int? = 0
|
||||
|
||||
fun box(): String {
|
||||
Value<Int>(42).let(Foo::foo)
|
||||
if (res != 42) return "FAIL 1 $res"
|
||||
res = 0
|
||||
|
||||
Value<Int>(42).let(Foo::bar)
|
||||
if (res != 42) return "FAIL 2 $res"
|
||||
res = 0
|
||||
|
||||
null.let(Foo::bar)
|
||||
if (res != null) return "FAIL 3: $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
@kotlin.Metadata
|
||||
public final class Foo {
|
||||
// source: 'intNGeneric2.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull field INSTANCE: Foo
|
||||
static method <clinit>(): void
|
||||
private method <init>(): void
|
||||
public final method bar-vRV1vHs(@org.jetbrains.annotations.Nullable p0: Value): void
|
||||
public final method foo-YR_CVCc(@org.jetbrains.annotations.NotNull p0: java.lang.Integer): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class IntNGeneric2Kt {
|
||||
// source: 'intNGeneric2.kt'
|
||||
private static @org.jetbrains.annotations.Nullable field res: java.lang.Integer
|
||||
static method <clinit>(): void
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static @org.jetbrains.annotations.Nullable method getRes(): java.lang.Integer
|
||||
public final static method setRes(@org.jetbrains.annotations.Nullable p0: java.lang.Integer): void
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline
|
||||
@kotlin.Metadata
|
||||
public final class Value {
|
||||
// source: 'intNGeneric2.kt'
|
||||
private final @org.jetbrains.annotations.Nullable field value: java.lang.Integer
|
||||
private synthetic method <init>(p0: java.lang.Integer): void
|
||||
public synthetic final static method box-impl(p0: java.lang.Integer): Value
|
||||
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.Nullable p0: java.lang.Integer): java.lang.Integer
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: java.lang.Integer, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: java.lang.Integer, p1: java.lang.Integer): boolean
|
||||
public final @org.jetbrains.annotations.Nullable method getValue(): java.lang.Integer
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: java.lang.Integer): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: java.lang.Integer): java.lang.String
|
||||
public synthetic final method unbox-impl(): java.lang.Integer
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Value<T: String>(val value: T?)
|
||||
|
||||
object Foo {
|
||||
fun foo(value: Value<String>) {
|
||||
res = value.value
|
||||
}
|
||||
|
||||
fun bar(value: Value<String>?) {
|
||||
res = value?.value
|
||||
}
|
||||
}
|
||||
|
||||
var res: String? = "FAIL"
|
||||
|
||||
fun box(): String {
|
||||
Value<String>("OK").let(Foo::foo)
|
||||
if (res != "OK") return "FAIL 1: $res"
|
||||
res = "FAIL 2"
|
||||
|
||||
Value<String>("OK").let(Foo::bar)
|
||||
if (res != "OK") return "FAIL 3: $res"
|
||||
res = "FAIL 4"
|
||||
|
||||
null.let(Foo::bar)
|
||||
if (res != null) return "FAIL 3: $res"
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -14,6 +14,10 @@ OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class WithNullableReference<T>(val a: T)
|
||||
fun <T> takeWithNullableReference(a: WithNullableReference<T>) {}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class WithNullableReference2<T: Any>(val a: T?)
|
||||
fun <T: Any> takeWithNullableReference2(a: WithNullableReference2<T>) {}
|
||||
|
||||
fun <T: Int> foo(a: WithPrimitive<T>?, b: WithPrimitive<T>) {
|
||||
takeWithPrimitive(a!!) // unbox
|
||||
takeWithPrimitive(a) // unbox
|
||||
@@ -33,6 +37,13 @@ fun <T, R> baz(a: WithNullableReference<T>?, b: WithNullableReference<R>) {
|
||||
takeWithNullableReference(b!!)
|
||||
}
|
||||
|
||||
fun <T: Any, R: Any> baz2(a: WithNullableReference2<T>?, b: WithNullableReference2<R>) {
|
||||
takeWithNullableReference2(a!!) // unbox
|
||||
takeWithNullableReference2(a) // unbox
|
||||
takeWithNullableReference2(a!!) // unbox
|
||||
takeWithNullableReference2(b!!)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a1 = WithPrimitive(1)
|
||||
val b1 = WithPrimitive(2)
|
||||
@@ -48,5 +59,10 @@ fun box(): String {
|
||||
|
||||
baz(a3, a4)
|
||||
|
||||
val a32 = WithNullableReference2("test")
|
||||
val a42 = WithNullableReference2(123)
|
||||
|
||||
baz2(a32, a42)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+13
@@ -14,6 +14,9 @@ value class InlineNotNullReference<T: Any>(val a: T)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class InlineNullableReference<T>(val a: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class InlineNullableReference2<T: Any>(val a: T?)
|
||||
|
||||
fun <T: Int> test1(a: InlineNotNullPrimitive<T>) {
|
||||
val a0 = a
|
||||
val a1: Any = a // box
|
||||
@@ -46,16 +49,26 @@ fun <T> test4(d: InlineNullableReference<T>) {
|
||||
val d4: InlineNullableReference<T>? = d // box
|
||||
}
|
||||
|
||||
fun <T: Any> test5(e: InlineNullableReference2<T>) {
|
||||
val e0 = e
|
||||
val e1: Any = e // box
|
||||
val e2: Any? = e // box
|
||||
val e3: InlineNullableReference2<T> = e
|
||||
val e4: InlineNullableReference2<T>? = e // box
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = InlineNotNullPrimitive(1)
|
||||
val b = InlineNullablePrimitive(1)
|
||||
val c = InlineNotNullReference("some")
|
||||
val d = InlineNullableReference("other")
|
||||
val e = InlineNullableReference2("other2")
|
||||
|
||||
test1(a)
|
||||
test2(b)
|
||||
test3(c)
|
||||
test4(d)
|
||||
test5(e)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Result<T: Any>(val a: T?) {
|
||||
fun typed(): T? = a
|
||||
}
|
||||
|
||||
fun <T: Any> takeResult(r: Result<T>) {}
|
||||
fun takeResultOfInt(r: Result<Int>) {}
|
||||
fun takeInt(i: Int) {}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val asInt = Result<Int>(19)
|
||||
val asString = Result<String>("sample")
|
||||
val asResult = Result<Result<Int>>(asInt)
|
||||
val asResultCtor = Result<Result<Int>>(Result<Int>(10))
|
||||
|
||||
takeResult(asInt)
|
||||
takeResult(asString)
|
||||
takeResult(asResult)
|
||||
takeResult(asResultCtor)
|
||||
|
||||
takeResultOfInt(asInt)
|
||||
takeInt(asInt.typed()!!)
|
||||
|
||||
val unboxedInt = asInt.typed()
|
||||
val unboxedString = asString.typed()
|
||||
val unboxedResult = asResult.typed()
|
||||
val unboxedAsCtor = asResultCtor.typed()
|
||||
|
||||
if (unboxedInt != 19) return "fail 1"
|
||||
if (unboxedString != "sample") return "fail 2"
|
||||
if (unboxedResult?.typed() != 19) return "fail 3"
|
||||
if (unboxedAsCtor?.typed() != 10) return "fail 4"
|
||||
|
||||
if (asResult?.typed()?.typed() != 19) return "fail 5"
|
||||
if (asResultCtor?.typed()?.typed() != 10) return "fail 6"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -18,6 +18,9 @@ value class IcLong<T: Long>(val l: T)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcAny<T>(val a: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcAny2<T: Any>(val a: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcOverIc<T: IcLong<Long>>(val o: T)
|
||||
|
||||
@@ -38,23 +41,27 @@ fun box(): String {
|
||||
val i = IcInt(0)
|
||||
val l = IcLong(0)
|
||||
val a = IcAny("foo")
|
||||
val a2 = IcAny2("foo2")
|
||||
val o = IcOverIc(IcLong(0))
|
||||
|
||||
check(i::class, "class root.IcInt")
|
||||
check(l::class, "class root.IcLong")
|
||||
check(a::class, "class root.IcAny")
|
||||
check(a2::class, "class root.IcAny2")
|
||||
check(o::class, "class root.IcOverIc")
|
||||
check(1u::class, "class kotlin.UInt")
|
||||
|
||||
check(i::class.simpleName, "IcInt")
|
||||
check(l::class.simpleName, "IcLong")
|
||||
check(a::class.simpleName, "IcAny")
|
||||
check(a2::class.simpleName, "IcAny2")
|
||||
check(o::class.simpleName, "IcOverIc")
|
||||
check(1u::class.simpleName, "UInt")
|
||||
|
||||
reifiedCheck<IcInt<Int>>("class root.IcInt", "IcInt")
|
||||
reifiedCheck<IcLong<Long>>("class root.IcLong", "IcLong")
|
||||
reifiedCheck<IcAny<Any?>>("class root.IcAny", "IcAny")
|
||||
reifiedCheck<IcAny2<Any>>("class root.IcAny2", "IcAny2")
|
||||
reifiedCheck<IcOverIc<IcLong<Long>>>("class root.IcOverIc", "IcOverIc")
|
||||
reifiedCheck<UInt>("class kotlin.UInt", "UInt")
|
||||
|
||||
@@ -67,6 +74,9 @@ fun box(): String {
|
||||
val arrA = arrayOf(a)
|
||||
check(arrA[0]::class, "class root.IcAny")
|
||||
|
||||
val arrA2 = arrayOf(a2)
|
||||
check(arrA2[0]::class, "class root.IcAny2")
|
||||
|
||||
val arrO = arrayOf(o)
|
||||
check(arrO[0]::class, "class root.IcOverIc")
|
||||
|
||||
@@ -76,6 +86,7 @@ fun box(): String {
|
||||
check(IcInt::class, "class root.IcInt")
|
||||
check(IcLong::class, "class root.IcLong")
|
||||
check(IcAny::class, "class root.IcAny")
|
||||
check(IcAny2::class, "class root.IcAny2")
|
||||
check(IcOverIc::class, "class root.IcOverIc")
|
||||
check(UInt::class, "class kotlin.UInt")
|
||||
|
||||
|
||||
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Result<T: Any>(val a: T?) {
|
||||
fun getOrThrow(): T? = a
|
||||
}
|
||||
|
||||
abstract class ResultReceiver<T: Any> {
|
||||
abstract fun receive(result: Result<T>)
|
||||
}
|
||||
|
||||
inline fun <T: Any> ResultReceiver(crossinline f: (Result<T>) -> Unit): ResultReceiver<T> =
|
||||
object : ResultReceiver<T>() {
|
||||
override fun receive(result: Result<T>) {
|
||||
f(result)
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
var invoked = false
|
||||
val receiver = ResultReceiver<String> { result ->
|
||||
val intResult = result.getOrThrow()
|
||||
invoked = true
|
||||
}
|
||||
|
||||
receiver.receive(Result("42"))
|
||||
if (!invoked) {
|
||||
throw RuntimeException("Fail")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test()
|
||||
return "OK"
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class A<T: Any>(val x: T?)
|
||||
|
||||
fun <T: Any> isNotNullVacuousLeft(s: A<T>) = s != null
|
||||
fun <T: Any> isNotNullVacuousRight(s: A<T>) = null != s
|
||||
fun <T: Any> isNotNullLeft(s: A<T>?) = s != null
|
||||
fun <T: Any> isNotNullRight(s: A<T>?) = null != s
|
||||
fun <T: Any> isNotEqualSame(s: A<T>, t: A<T>) = s != t
|
||||
fun <T: Any> isNotEqualAnyLeft(s: A<T>, t: Any?) = s != t
|
||||
fun <T: Any> isNotEqualAnyRight(s: Any?, t: A<T>) = s != t
|
||||
fun <T: Any> isNotEqualSameNullable(s: A<T>?, t: A<T>?) = s != t
|
||||
fun <T: Any> isNotEqualAnyNullableLeft(s: A<T>?, t: Any?) = s != t
|
||||
fun <T: Any> isNotEqualAnyNullableRight(s: Any?, t: A<T>?) = s != t
|
||||
fun <T: Any> isNotEqualNullableUnboxedLeft(s: A<T>, t: A<T>?) = s != t
|
||||
fun <T: Any> isNotEqualNullableUnboxedRight(s: A<T>?, t: A<T>) = s != t
|
||||
|
||||
fun box(): String {
|
||||
if (!isNotNullVacuousLeft(A(0))) return "Fail 1"
|
||||
if (!isNotNullVacuousRight(A(0))) return "Fail 2"
|
||||
if (!isNotNullLeft(A(0))) return "Fail 3"
|
||||
if (!isNotNullRight(A(0))) return "Fail 4"
|
||||
if (isNotNullLeft<Any>(null)) return "Fail 5"
|
||||
if (isNotNullRight<Any>(null)) return "Fail 6"
|
||||
if (isNotEqualSame(A(0), A(0))) return "Fail 7"
|
||||
if (!isNotEqualSame(A(0), A(1))) return "Fail 8"
|
||||
if (!isNotEqualAnyLeft(A(0), 0)) return "Fail 9"
|
||||
if (!isNotEqualAnyLeft(A(0), null)) return "Fail 10"
|
||||
if (isNotEqualAnyLeft(A(0), A(0))) return "Fail 11"
|
||||
if (!isNotEqualAnyRight(0, A(0))) return "Fail 12"
|
||||
if (!isNotEqualAnyRight(null, A(0))) return "Fail 13"
|
||||
if (isNotEqualAnyRight(A(0), A(0))) return "Fail 14"
|
||||
if (isNotEqualSameNullable<Any>(null, null)) return "Fail 15"
|
||||
if (isNotEqualSameNullable(A(0), A(0))) return "Fail 16"
|
||||
if (!isNotEqualSameNullable(null, A(0))) return "Fail 17"
|
||||
if (!isNotEqualSameNullable(A(0), null)) return "Fail 18"
|
||||
if (!isNotEqualSameNullable(A(0), A(1))) return "Fail 19"
|
||||
if (isNotEqualAnyNullableLeft<Any>(null, null)) return "Fail 20"
|
||||
if (isNotEqualAnyNullableLeft(A(0), A(0))) return "Fail 21"
|
||||
if (!isNotEqualAnyNullableLeft(A(0), 0)) return "Fail 22"
|
||||
if (!isNotEqualAnyNullableLeft<Any>(null, 0)) return "Fail 23"
|
||||
if (!isNotEqualAnyNullableLeft(A(0), null)) return "Fail 24"
|
||||
if (!isNotEqualAnyNullableLeft(A(0), A(1))) return "Fail 25"
|
||||
if (isNotEqualAnyNullableRight<Any>(null, null)) return "Fail 26"
|
||||
if (isNotEqualAnyNullableRight(A(0), A(0))) return "Fail 27"
|
||||
if (!isNotEqualAnyNullableRight(0, A(0))) return "Fail 28"
|
||||
if (!isNotEqualAnyNullableRight<Any>(0, null)) return "Fail 29"
|
||||
if (!isNotEqualAnyNullableRight(null, A(0))) return "Fail 30"
|
||||
if (!isNotEqualAnyNullableRight(A(0), A(1))) return "Fail 31"
|
||||
|
||||
if (!isNotNullVacuousLeft(A(null))) return "Fail 32"
|
||||
if (!isNotNullVacuousRight(A(null))) return "Fail 33"
|
||||
if (!isNotNullLeft(A(null))) return "Fail 34"
|
||||
if (!isNotNullRight(A(null))) return "Fail 35"
|
||||
if (!isNotEqualAnyLeft(A(null), null)) return "Fail 36"
|
||||
if (!isNotEqualAnyRight(null, A(null))) return "Fail 37"
|
||||
if (!isNotEqualAnyNullableLeft(A(null), null)) return "Fail 38"
|
||||
if (!isNotEqualAnyNullableRight(null, A(null))) return "Fail 39"
|
||||
if (!isNotEqualSameNullable(A(null), null)) return "Fail 42"
|
||||
if (!isNotEqualSameNullable(null, A(null))) return "Fail 43"
|
||||
|
||||
if (!isNotEqualNullableUnboxedLeft(A(0), A(1))) return "Fail 44"
|
||||
if (isNotEqualNullableUnboxedLeft(A(0), A(0))) return "Fail 45"
|
||||
if (!isNotEqualNullableUnboxedRight(A(0), A(1))) return "Fail 46"
|
||||
if (isNotEqualNullableUnboxedRight(A(1), A(1))) return "Fail 47"
|
||||
if (!isNotEqualNullableUnboxedLeft(A(0), null)) return "Fail 48"
|
||||
if (!isNotEqualNullableUnboxedRight(null, A(1))) return "Fail 49"
|
||||
|
||||
if (!isNotEqualNullableUnboxedRight(null, A(null))) return "Fail 50"
|
||||
if (!isNotEqualNullableUnboxedLeft(A(null), null)) return "Fail 51"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class A<T: Any>(val x: T?)
|
||||
|
||||
fun <T: Any> isNullVacuousLeft(s: A<T>) = s == null
|
||||
fun <T: Any> isNullVacuousRight(s: A<T>) = null == s
|
||||
fun <T: Any> isNullLeft(s: A<T>?) = s == null
|
||||
fun <T: Any> isNullRight(s: A<T>?) = null == s
|
||||
fun <T: Any> isEqualSame(s: A<T>, t: A<T>) = s == t
|
||||
fun <T: Any> isEqualAnyLeft(s: A<T>, t: Any?) = s == t
|
||||
fun <T: Any> isEqualAnyRight(s: Any?, t: A<T>) = s == t
|
||||
fun <T: Any> isEqualSameNullable(s: A<T>?, t: A<T>?) = s == t
|
||||
fun <T: Any> isEqualAnyNullableLeft(s: A<T>?, t: Any?) = s == t
|
||||
fun <T: Any> isEqualAnyNullableRight(s: Any?, t: A<T>?) = s == t
|
||||
fun <T: Any> isEqualNullableUnboxedLeft(s: A<T>, t: A<T>?) = s == t
|
||||
fun <T: Any> isEqualNullableUnboxedRight(s: A<T>?, t: A<T>) = s == t
|
||||
|
||||
fun box(): String {
|
||||
if (isNullVacuousLeft(A(0))) return "Fail 1"
|
||||
if (isNullVacuousRight(A(0))) return "Fail 2"
|
||||
if (isNullLeft(A(0))) return "Fail 3"
|
||||
if (isNullRight(A(0))) return "Fail 4"
|
||||
if (!isNullLeft<Any>(null)) return "Fail 5"
|
||||
if (!isNullRight<Any>(null)) return "Fail 6"
|
||||
if (!isEqualSame(A(0), A(0))) return "Fail 7"
|
||||
if (isEqualSame(A(0), A(1))) return "Fail 8"
|
||||
if (isEqualAnyLeft(A(0), 0)) return "Fail 9"
|
||||
if (isEqualAnyLeft(A(0), null)) return "Fail 10"
|
||||
if (!isEqualAnyLeft(A(0), A(0))) return "Fail 11"
|
||||
if (isEqualAnyRight(0, A(0))) return "Fail 12"
|
||||
if (isEqualAnyRight(null, A(0))) return "Fail 13"
|
||||
if (!isEqualAnyRight(A(0), A(0))) return "Fail 14"
|
||||
if (!isEqualSameNullable<Any>(null, null)) return "Fail 15"
|
||||
if (!isEqualSameNullable(A(0), A(0))) return "Fail 16"
|
||||
if (isEqualSameNullable(null, A(0))) return "Fail 17"
|
||||
if (isEqualSameNullable(A(0), null)) return "Fail 18"
|
||||
if (isEqualSameNullable(A(0), A(1))) return "Fail 19"
|
||||
if (!isEqualAnyNullableLeft<Any>(null, null)) return "Fail 20"
|
||||
if (!isEqualAnyNullableLeft(A(0), A(0))) return "Fail 21"
|
||||
if (isEqualAnyNullableLeft(A(0), 0)) return "Fail 22"
|
||||
if (isEqualAnyNullableLeft<Any>(null, 0)) return "Fail 23"
|
||||
if (isEqualAnyNullableLeft(A(0), null)) return "Fail 24"
|
||||
if (isEqualAnyNullableLeft(A(0), A(1))) return "Fail 25"
|
||||
if (!isEqualAnyNullableRight<Any>(null, null)) return "Fail 26"
|
||||
if (!isEqualAnyNullableRight(A(0), A(0))) return "Fail 27"
|
||||
if (isEqualAnyNullableRight(0, A(0))) return "Fail 28"
|
||||
if (isEqualAnyNullableRight<Any>(0, null)) return "Fail 29"
|
||||
if (isEqualAnyNullableRight(null, A(0))) return "Fail 30"
|
||||
if (isEqualAnyNullableRight(A(0), A(1))) return "Fail 31"
|
||||
|
||||
if (isNullVacuousLeft(A(null))) return "Fail 32"
|
||||
if (isNullVacuousRight(A(null))) return "Fail 33"
|
||||
if (isNullLeft(A(null))) return "Fail 34"
|
||||
if (isNullRight(A(null))) return "Fail 35"
|
||||
if (isEqualAnyLeft(A(null), null)) return "Fail 36"
|
||||
if (isEqualAnyRight(null, A(null))) return "Fail 37"
|
||||
if (isEqualAnyNullableLeft(A(null), null)) return "Fail 38"
|
||||
if (isEqualAnyNullableRight(null, A(null))) return "Fail 39"
|
||||
if (isEqualSameNullable(A(null), null)) return "Fail 42"
|
||||
if (isEqualSameNullable(null, A(null))) return "Fail 43"
|
||||
|
||||
if (isEqualNullableUnboxedLeft(A(0), A(1))) return "Fail 44"
|
||||
if (!isEqualNullableUnboxedLeft(A(0), A(0))) return "Fail 45"
|
||||
if (isEqualNullableUnboxedRight(A(0), A(1))) return "Fail 46"
|
||||
if (!isEqualNullableUnboxedRight(A(1), A(1))) return "Fail 47"
|
||||
if (isEqualNullableUnboxedLeft(A(0), null)) return "Fail 48"
|
||||
if (isEqualNullableUnboxedRight(null, A(1))) return "Fail 49"
|
||||
|
||||
if (isEqualNullableUnboxedRight(null, A(null))) return "Fail 50"
|
||||
if (isEqualNullableUnboxedLeft(A(null), null)) return "Fail 51"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+29
@@ -13,9 +13,16 @@ value class Y<T: Number>(val y: T)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class NX<T: String?>(val x: T)
|
||||
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class NX2<T: String>(val x: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class NY<T: Number?>(val y: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class NY2<T: Number>(val y: T?)
|
||||
|
||||
fun testNotNull(x: X<String>?, y: Y<Number>?) {
|
||||
val xs = listOf<Any?>(x)
|
||||
val ys = listOf<Any?>(y)
|
||||
@@ -32,6 +39,14 @@ fun testNullable(x: NX<String?>?, y: NY<Number?>?) {
|
||||
if (xs[0] === ys[0]) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testNullable2(x: NX2<String>?, y: NY2<Number>?) {
|
||||
val xs = listOf<Any?>(x)
|
||||
val ys = listOf<Any?>(y)
|
||||
if (xs.contains(y)) throw AssertionError()
|
||||
if (xs[0] == ys[0]) throw AssertionError()
|
||||
if (xs[0] === ys[0]) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testNullsAsNullable(x: NX<String?>?, y: NY<Number?>?) {
|
||||
val xs = listOf<Any?>(x)
|
||||
val ys = listOf<Any?>(y)
|
||||
@@ -40,6 +55,14 @@ fun testNullsAsNullable(x: NX<String?>?, y: NY<Number?>?) {
|
||||
if (xs[0] !== ys[0]) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testNullsAsNullable2(x: NX2<String>?, y: NY2<Number>?) {
|
||||
val xs = listOf<Any?>(x)
|
||||
val ys = listOf<Any?>(y)
|
||||
if (!xs.contains(y)) throw AssertionError()
|
||||
if (xs[0] != ys[0]) throw AssertionError()
|
||||
if (xs[0] !== ys[0]) throw AssertionError()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
testNotNull(null, null)
|
||||
@@ -48,7 +71,13 @@ fun box(): String {
|
||||
testNullable(NX(null), null)
|
||||
testNullable(null, NY(null))
|
||||
|
||||
testNullable2(NX2(null), NY2(null))
|
||||
testNullable2(NX2(null), null)
|
||||
testNullable2(null, NY2(null))
|
||||
|
||||
testNullsAsNullable(null, null)
|
||||
|
||||
testNullsAsNullable2(null, null)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class A<T: Any>(val x: T? = null)
|
||||
|
||||
var i = 0
|
||||
|
||||
fun set1(): A<Any> {
|
||||
i = 1
|
||||
return A()
|
||||
}
|
||||
|
||||
fun test1(n: Int): A<Any> {
|
||||
if (i != 1)
|
||||
throw IllegalStateException("Fail $n")
|
||||
i = 0
|
||||
return A()
|
||||
}
|
||||
|
||||
fun set1Boxed(): Any? = set1()
|
||||
fun test1Boxed(n: Int): Any? = test1(n)
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
set1() == test1(1)
|
||||
set1Boxed() == test1(2)
|
||||
set1() == test1Boxed(3)
|
||||
set1Boxed() == test1Boxed(4)
|
||||
} catch (e: IllegalStateException) {
|
||||
return e.message ?: "Fail no message"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+9
@@ -5,6 +5,8 @@
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcAny<T>(val x: T)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcAny2<T: Any>(val x: T?)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcInt<T: Int>(val x: T)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcLong<T: Long>(val x: T)
|
||||
@@ -33,5 +35,12 @@ fun box(): String {
|
||||
if (id(IcAny(42)) == id(IcAny(24))) return "Error 3, 5"
|
||||
if (id(IcAny(42)) != id(IcAny(42))) return "Error 3, 6"
|
||||
|
||||
if (IcAny2(42) == id(IcAny2(24))) return "Error 4, 1"
|
||||
if (IcAny2(42) != id(IcAny2(42))) return "Error 4, 2"
|
||||
if (id(IcAny2(42)) == IcAny2(24)) return "Error 4, 3"
|
||||
if (id(IcAny2(42)) != IcAny2(42)) return "Error 4, 4"
|
||||
if (id(IcAny2(42)) == id(IcAny2(24))) return "Error 4, 5"
|
||||
if (id(IcAny2(42)) != id(IcAny2(42))) return "Error 4, 6"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Result<T: Any>(val isSuccess: T?)
|
||||
|
||||
fun interface ResultHandler<T: Any> {
|
||||
fun onResult(result: Result<T>)
|
||||
}
|
||||
|
||||
fun doSmth(resultHandler: ResultHandler<Boolean>) {
|
||||
resultHandler.onResult(Result(true))
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var res = "FAIL"
|
||||
doSmth { result ->
|
||||
res = if (result.isSuccess == true) "OK" else "FAIL 1"
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_STDLIB
|
||||
// IGNORE_BACKEND: JVM
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Result<T: Any>(val isSuccess: T?)
|
||||
|
||||
fun interface ResultHandler<T: Any> {
|
||||
fun onResult(): Result<T>
|
||||
}
|
||||
|
||||
fun doSmth(resultHandler: ResultHandler<Boolean>): Result<Boolean> {
|
||||
return resultHandler.onResult()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var res = doSmth { Result(true) }
|
||||
return if (res.isSuccess == true) "OK" else "FAIL"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// CHECK_BYTECODE_LISTING
|
||||
// LANGUAGE: -JvmInlineValueClasses, +GenericInlineClassParameter
|
||||
// IGNORE_BACKED: JVM
|
||||
|
||||
inline class ICAny<T: Any>(val value: T?)
|
||||
|
||||
fun box(): String = ICAny("OK").value.toString()
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
@kotlin.jvm.JvmInline
|
||||
@kotlin.Metadata
|
||||
public final class ICAny {
|
||||
// source: 'simple2.kt'
|
||||
private final @org.jetbrains.annotations.Nullable field value: java.lang.Object
|
||||
private synthetic method <init>(p0: java.lang.Object): void
|
||||
public synthetic final static method box-impl(p0: java.lang.Object): ICAny
|
||||
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: java.lang.Object, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: java.lang.Object, p1: java.lang.Object): boolean
|
||||
public final @org.jetbrains.annotations.Nullable method getValue(): java.lang.Object
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: java.lang.Object): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: java.lang.Object): java.lang.String
|
||||
public synthetic final method unbox-impl(): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class Simple2Kt {
|
||||
// source: 'simple2.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
}
|
||||
@@ -19,6 +19,16 @@ value class MultipleInitBlocks<T>(val a: T) {
|
||||
}
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class MultipleInitBlocks2<T: Any>(val a: T?) {
|
||||
init {
|
||||
res = "O"
|
||||
}
|
||||
init {
|
||||
res += "K"
|
||||
}
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Lambda<T: String>(val s: T) {
|
||||
init {
|
||||
@@ -137,6 +147,10 @@ fun box(): String {
|
||||
MultipleInitBlocks(null)
|
||||
if (res != "OK") return "FAIL 21: $res"
|
||||
|
||||
res = "FAIL 22"
|
||||
MultipleInitBlocks2(null)
|
||||
if (res != "OK") return "FAIL 221: $res"
|
||||
|
||||
res = "FAIL 3"
|
||||
Lambda("OK")
|
||||
if (res != "OK") return "FAIL 31: $res"
|
||||
|
||||
+9
@@ -11,12 +11,17 @@ value class Str<T: String>(val string: T)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class NStr<T: String?>(val string: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class NStr2<T: String>(val string: T?)
|
||||
|
||||
fun <T: Int> fooZ(x: Z<T>) = x
|
||||
|
||||
fun <T: String> fooStr(x: Str<T>) = x
|
||||
|
||||
fun <T: String?> fooNStr(x: NStr<T>) = x
|
||||
|
||||
fun <T: String> fooNStr2(x: NStr2<T>) = x
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val fnZ: (Z<Int>) -> Z<Int> = ::fooZ
|
||||
@@ -29,5 +34,9 @@ fun box(): String {
|
||||
if (fnNStr.invoke(NStr(null)).string != null) throw AssertionError()
|
||||
if (fnNStr.invoke(NStr("nstr")).string != "nstr") throw AssertionError()
|
||||
|
||||
val fnNStr2: (NStr2<String>) -> NStr2<String> = ::fooNStr2
|
||||
if (fnNStr2.invoke(NStr2(null)).string != null) throw AssertionError()
|
||||
if (fnNStr2.invoke(NStr2("nstr2")).string != "nstr2") throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -5,6 +5,9 @@
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class AsAny<T>(val x: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class AsAny2<T: Any>(val x: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class AsInt<T: Int>(val x: T)
|
||||
|
||||
@@ -18,6 +21,14 @@ object Reference {
|
||||
fun <T, R> transformNullableToNullableTarget(a: AsAny<T>?): AsAny<R>? = a as AsAny<R>?
|
||||
}
|
||||
|
||||
object Reference2 {
|
||||
fun <T: Any, R: Any> transform(a: AsAny2<T>): AsAny2<R> = a as AsAny2<R>
|
||||
fun <T: Any, R: Any> transformNullable(a: AsAny2<T>?): AsAny2<R> = a as AsAny2<R>
|
||||
fun <T: Any, R: Any> transformToNullable(a: AsAny2<T>): AsAny2<R>? = a as AsAny2<R>
|
||||
fun <T: Any, R: Any> transformToNullableTarget(a: AsAny2<T>): AsAny2<R>? = a as AsAny2<R>?
|
||||
fun <T: Any, R: Any> transformNullableToNullableTarget(a: AsAny2<T>?): AsAny2<R>? = a as AsAny2<R>?
|
||||
}
|
||||
|
||||
object Primitive {
|
||||
fun <T: Int> transform(a: AsInt<T>): AsInt<T> = a as AsInt<T>
|
||||
fun <T: Int> transformNullable(a: AsInt<T>?): AsInt<T> = a as AsInt<T>
|
||||
@@ -38,6 +49,17 @@ fun box(): String {
|
||||
val b7 = a.checkcast<AsAny<Number>>()
|
||||
if (b7.x != a.x) return "Fail 1"
|
||||
|
||||
val a2 = AsAny2<Int>(42)
|
||||
val b21 = Reference2.transform<Int, Number>(a2)
|
||||
val b22 = Reference2.transformNullable<Int, Number>(a2)
|
||||
val b23 = Reference2.transformToNullable<Int, Number>(a2)
|
||||
val b24 = Reference2.transformToNullableTarget<Int, Number>(a2)
|
||||
val b25 = Reference2.transformNullableToNullableTarget<Int, Number>(a2)
|
||||
val b26 = Reference2.transformNullableToNullableTarget<Int, Number>(null)
|
||||
|
||||
val b72 = a2.checkcast<AsAny2<Number>>()
|
||||
if (b72.x != a2.x) return "Fail 12"
|
||||
|
||||
val c = AsInt(42)
|
||||
val d1 = Primitive.transform(c)
|
||||
val d2 = Primitive.transformNullable(c)
|
||||
|
||||
+10
@@ -15,6 +15,9 @@ value class IcLong<T: Long>(val l: T)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcAny<T>(val a: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcAny2<T: Any>(val a: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcOverIc<T: IcLong<Long>>(val o: T)
|
||||
|
||||
@@ -30,23 +33,27 @@ fun box(): String {
|
||||
val i = IcInt(0)
|
||||
val l = IcLong(0)
|
||||
val a = IcAny("foo")
|
||||
val a2 = IcAny2("foo2")
|
||||
val o = IcOverIc(IcLong(0))
|
||||
|
||||
check(i.javaClass, "class root.IcInt")
|
||||
check(l.javaClass, "class root.IcLong")
|
||||
check(a.javaClass, "class root.IcAny")
|
||||
check(a2.javaClass, "class root.IcAny2")
|
||||
check(o.javaClass, "class root.IcOverIc")
|
||||
check(1u.javaClass, "class kotlin.UInt")
|
||||
|
||||
check(i::class.java, "class root.IcInt")
|
||||
check(l::class.java, "class root.IcLong")
|
||||
check(a::class.java, "class root.IcAny")
|
||||
check(a2::class.java, "class root.IcAny2")
|
||||
check(o::class.java, "class root.IcOverIc")
|
||||
check(1u::class.java, "class kotlin.UInt")
|
||||
|
||||
reifiedCheck<IcInt<Int>>("class root.IcInt")
|
||||
reifiedCheck<IcLong<Long>>("class root.IcLong")
|
||||
reifiedCheck<IcAny<Any?>>("class root.IcAny")
|
||||
reifiedCheck<IcAny2<Any>>("class root.IcAny2")
|
||||
reifiedCheck<IcOverIc<IcLong<Long>>>("class root.IcOverIc")
|
||||
reifiedCheck<UInt>("class kotlin.UInt")
|
||||
|
||||
@@ -59,6 +66,9 @@ fun box(): String {
|
||||
val arrA = arrayOf(a)
|
||||
check(arrA[0].javaClass, "class root.IcAny")
|
||||
|
||||
val arrA2 = arrayOf(a2)
|
||||
check(arrA2[0].javaClass, "class root.IcAny2")
|
||||
|
||||
val arrO = arrayOf(o)
|
||||
check(arrO[0].javaClass, "class root.IcOverIc")
|
||||
|
||||
|
||||
@@ -14,13 +14,18 @@ value class JLI<T: java.lang.Integer>(val x: T)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class U<T: Unit?>(val x: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class U2<T: Unit>(val x: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class N<T: Nothing?>(val x: T)
|
||||
|
||||
val icUnit = U(Unit)
|
||||
val icUnit2 = U2(Unit)
|
||||
val icNull = N(null)
|
||||
|
||||
val anyIcUnit: Any = icUnit
|
||||
val anyIcUnit2: Any = icUnit2
|
||||
val anyIcNull: Any = icNull
|
||||
|
||||
val z = I(42)
|
||||
@@ -28,13 +33,16 @@ val jli = JLI(java.lang.Integer(42))
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(null, icUnit::class.javaPrimitiveType)
|
||||
assertEquals(null, icUnit2::class.javaPrimitiveType)
|
||||
assertEquals(null, icNull::class.javaPrimitiveType)
|
||||
assertEquals(null, anyIcUnit::class.javaPrimitiveType)
|
||||
assertEquals(null, anyIcUnit2::class.javaPrimitiveType)
|
||||
assertEquals(null, anyIcNull::class.javaPrimitiveType)
|
||||
assertEquals(null, z::class.javaPrimitiveType)
|
||||
assertEquals(null, jli::class.javaPrimitiveType)
|
||||
|
||||
assertEquals(null, U::class.javaPrimitiveType)
|
||||
assertEquals(null, U2::class.javaPrimitiveType)
|
||||
assertEquals(null, N::class.javaPrimitiveType)
|
||||
assertEquals(null, I::class.javaPrimitiveType)
|
||||
assertEquals(null, JLI::class.javaPrimitiveType)
|
||||
|
||||
@@ -16,6 +16,9 @@ value class ICIntArray(val i: IntArray)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class ICIntN<T: Int?>(val i: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class ICIntN2<T: Int>(val i: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class ICIntNArray(val i: Array<Int?>)
|
||||
|
||||
@@ -43,6 +46,10 @@ class CIntArray
|
||||
@AnnArray([ICIntN::class])
|
||||
class CIntN
|
||||
|
||||
@Ann(ICIntN2::class)
|
||||
@AnnArray([ICIntN2::class])
|
||||
class CIntN2
|
||||
|
||||
@Ann(ICIntNArray::class)
|
||||
@AnnArray([ICIntNArray::class])
|
||||
class CIntNArray
|
||||
@@ -73,6 +80,9 @@ fun box(): String {
|
||||
klass = (CIntN::class.annotations.first() as Ann).c.toString()
|
||||
if (klass != "class test.ICIntN") return "Expected class test.ICIntN, got $klass"
|
||||
|
||||
klass = (CIntN2::class.annotations.first() as Ann).c.toString()
|
||||
if (klass != "class test.ICIntN2") return "Expected class test.ICIntN2, got $klass"
|
||||
|
||||
klass = (CIntNArray::class.annotations.first() as Ann).c.toString()
|
||||
if (klass != "class test.ICIntNArray") return "Expected class test.ICIntNArray, got $klass"
|
||||
|
||||
@@ -98,6 +108,9 @@ fun box(): String {
|
||||
klass = (CIntN::class.annotations.last() as AnnArray).c[0].toString()
|
||||
if (klass != "class test.ICIntN") return "Expected class test.ICIntN, got $klass"
|
||||
|
||||
klass = (CIntN2::class.annotations.last() as AnnArray).c[0].toString()
|
||||
if (klass != "class test.ICIntN2") return "Expected class test.ICIntN2, got $klass"
|
||||
|
||||
klass = (CIntNArray::class.annotations.last() as AnnArray).c[0].toString()
|
||||
if (klass != "class test.ICIntNArray") return "Expected class test.ICIntNArray, got $klass"
|
||||
|
||||
|
||||
+8
@@ -6,6 +6,9 @@
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class GList<T>(val xs: List<T>)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class GList2<T: Any>(val xs: List<T?>)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class GSList<T>(val ss: List<String>)
|
||||
|
||||
@@ -31,6 +34,10 @@ fun testGList(gl: GList<String>) {
|
||||
if (gl.xs[0] != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun testGList2(gl: GList2<String>) {
|
||||
if (gl.xs[0] != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun testGSList(sl: GSList<String>) {
|
||||
if (sl.ss[0] != "OK") throw AssertionError()
|
||||
}
|
||||
@@ -57,6 +64,7 @@ fun testGIIList(giil: GIIList<Any>) {
|
||||
|
||||
fun box(): String {
|
||||
testGList(GList(listOf("OK")))
|
||||
testGList2(GList2(listOf("OK")))
|
||||
testGSList(GSList(listOf("OK")))
|
||||
testSList(SList(listOf("OK")))
|
||||
testIList(IList(listOf(42)))
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Z1<T: Int>(val x: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Z2<T: Z1<Int>>(val z: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class ZN<T: Z1<Int>?>(val z: T)
|
||||
|
||||
fun wrap1(n: Int): Z1<Int>? = if (n < 0) null else Z1(n)
|
||||
fun wrap2(n: Int): Z2<Z1<Int>>? = if (n < 0) null else Z2(Z1(n))
|
||||
fun wrapN(n: Int): ZN<Z1<Int>?>? = if (n < 0) null else ZN(Z1(n))
|
||||
|
||||
fun box(): String {
|
||||
if (wrap1(-1) != null) throw AssertionError()
|
||||
if (wrap1(42) == null) throw AssertionError()
|
||||
if (wrap1(42)!!.x != 42) throw AssertionError()
|
||||
|
||||
if (wrap2(-1) != null) throw AssertionError()
|
||||
if (wrap2(42) == null) throw AssertionError()
|
||||
if (wrap2(42)!!.z.x != 42) throw AssertionError()
|
||||
|
||||
if (wrapN(-1) != null) throw AssertionError()
|
||||
if (wrapN(42) == null) throw AssertionError()
|
||||
if (wrapN(42)!!.z!!.x != 42) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Z1<T: String>(val x: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Z2<T: Z1<String>>(val z: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class ZN<T: Z1<String>?>(val z: T)
|
||||
|
||||
fun wrap1(x: String): Z1<String>? = if (x.length == 0) null else Z1(x)
|
||||
fun wrap2(x: String): Z2<Z1<String>>? = if (x.length == 0) null else Z2(Z1(x))
|
||||
fun wrapN(x: String): ZN<Z1<String>?>? = if (x.length == 0) null else ZN(Z1(x))
|
||||
|
||||
fun box(): String {
|
||||
if (wrap1("") != null) throw AssertionError()
|
||||
if (wrap1("a") == null) throw AssertionError()
|
||||
if (wrap1("a")!!.x != "a") throw AssertionError()
|
||||
|
||||
if (wrap2("") != null) throw AssertionError()
|
||||
if (wrap2("a") == null) throw AssertionError()
|
||||
if (wrap2("a")!!.z.x != "a") throw AssertionError()
|
||||
|
||||
if (wrapN("") != null) throw AssertionError()
|
||||
if (wrapN("a") == null) throw AssertionError()
|
||||
if (wrapN("a")!!.z!!.x != "a") throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Location <T : String> @JvmOverloads constructor(val value: T? = "OK" as T)
|
||||
|
||||
fun box(): String = Location<String>().value!!
|
||||
@@ -1,6 +1,5 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Inlined(val value: Int)
|
||||
|
||||
Vendored
+6
@@ -21,6 +21,9 @@ value class IcLong<T: Long>(val l: T)
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcAny<T: Any?>(val a: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcAny2<T: Any>(val a: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IcOverIc<T: IcInt<Int>>(val o: T)
|
||||
|
||||
@@ -28,16 +31,19 @@ fun box(): String {
|
||||
val i = IcInt(1)
|
||||
val l = IcLong(2)
|
||||
val a = IcAny("string")
|
||||
val a2 = IcAny("string2")
|
||||
val o = IcOverIc(IcInt(3))
|
||||
|
||||
val ij = JavaClass.id(i)
|
||||
val lj = JavaClass.id(l)
|
||||
val aj = JavaClass.id(a)
|
||||
val aj2 = JavaClass.id(a2)
|
||||
val oj = JavaClass.id(o)
|
||||
|
||||
if (ij.i != 1) return "Fail 1"
|
||||
if (lj.l != 2L) return "Fail 2"
|
||||
if (aj.a != "string") return "Fail 3"
|
||||
if (aj2.a != "string2") return "Fail 32"
|
||||
if (oj.o.i != 3) return "Fail 4"
|
||||
|
||||
return "OK"
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Z1<T: String>(val x: T)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class ZN<T: Z1<String>>(val z: T?)
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class ZN2<TN: ZN<Z1<String>>>(val z: TN)
|
||||
|
||||
fun zap(b: Boolean): ZN2<ZN<Z1<String>>>? = if (b) null else ZN2(ZN(null))
|
||||
|
||||
fun eq(a: Any?, b: Any?) = a == b
|
||||
|
||||
fun box(): String {
|
||||
val x = zap(true)
|
||||
val y = zap(false)
|
||||
if (eq(x, y)) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// IGNORE_BACKEND: WASM, JS_IR
|
||||
// IGNORE_BACKEND: ANDROID
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// ALLOW_KOTLIN_PACKAGE
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
// FILE: result.kt
|
||||
package kotlin
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Result<T: Any>(val value: T?)
|
||||
|
||||
// FILE: box.kt
|
||||
|
||||
fun box(): String {
|
||||
return Result("OK").value!!
|
||||
}
|
||||
+27
@@ -9,6 +9,13 @@ value class AsAny<T>(val a: T) {
|
||||
}
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class AsAny2<T: Any>(val a: T?) {
|
||||
fun myEq(other: Any?): Boolean {
|
||||
return other is AsAny2<*> && other.a == a
|
||||
}
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class AsInt<T: Int>(val a: T) {
|
||||
fun myEq(other: Any?): Boolean {
|
||||
@@ -25,6 +32,13 @@ object Reference {
|
||||
fun <T> isNullableNotNullable(a: AsAny<T>?) = a is AsAny<*>
|
||||
}
|
||||
|
||||
object Reference2 {
|
||||
fun <T: Any> isNullable(a: AsAny2<T>) = a is AsAny2<*>?
|
||||
fun <T: Any> isNotNullable(a: AsAny2<T>) = a is AsAny2<*>
|
||||
fun <T: Any> isNullableNullable(a: AsAny2<T>?) = a is AsAny2<*>?
|
||||
fun <T: Any> isNullableNotNullable(a: AsAny2<T>?) = a is AsAny2<*>
|
||||
}
|
||||
|
||||
object Primitive {
|
||||
fun <T: Int> isNullable(a: AsInt<T>) = a is AsInt<*>?
|
||||
fun <T: Int> isNotNullable(a: AsInt<T>) = a is AsInt<*>
|
||||
@@ -35,6 +49,8 @@ object Primitive {
|
||||
fun box(): String {
|
||||
val a = AsAny(42)
|
||||
val b = AsAny(40 + 2)
|
||||
val a2 = AsAny2(42)
|
||||
val b2 = AsAny2(40 + 2)
|
||||
|
||||
if (!a.myEq(b)) return "Fail 1"
|
||||
if (a.myEq(42)) return "Fail 2"
|
||||
@@ -47,6 +63,13 @@ fun box(): String {
|
||||
if (!Reference.isNullableNotNullable(a)) return "Fail 8"
|
||||
if (Reference.isNullableNotNullable<Int>(null)) return "Fail 9"
|
||||
|
||||
if (!Reference2.isNullable(a2)) return "Fail 42"
|
||||
if (!Reference2.isNotNullable(a2)) return "Fail 52"
|
||||
if (!Reference2.isNullableNullable(a2)) return "Fail 62"
|
||||
if (!Reference2.isNullableNullable<Int>(null)) return "Fail 72"
|
||||
if (!Reference2.isNullableNotNullable(a2)) return "Fail 82"
|
||||
if (Reference2.isNullableNotNullable<Int>(null)) return "Fail 92"
|
||||
|
||||
val c = AsInt(42)
|
||||
val d = AsInt(40 + 2)
|
||||
if (!c.myEq(d)) return "Fail 10"
|
||||
@@ -68,5 +91,9 @@ fun box(): String {
|
||||
if (!c.isCheck<AsInt<Int>?>()) return "Fail 23"
|
||||
if (c.isCheck<AsAny<Int>>()) return "Fail 24"
|
||||
|
||||
if (!a2.isCheck<AsAny2<Int>>()) return "Fail 192"
|
||||
if (!a2.isCheck<AsAny2<Int>?>()) return "Fail 202"
|
||||
if (a2.isCheck<AsInt<Int>>()) return "Fail 212"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// 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 interface FunIFace<T, R> {
|
||||
fun call(ic: T): R
|
||||
}
|
||||
|
||||
fun <T, R> bar(value: T, f: FunIFace<T, R>): R {
|
||||
return f.call(value)
|
||||
}
|
||||
|
||||
fun <T: Any> IC<T>.extensionValue(): T? = value
|
||||
|
||||
fun <T: Any> normalValue(ic: IC<T>): T? = ic.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) "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"
|
||||
}
|
||||
+12
-12
@@ -3,19 +3,19 @@
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
fun <T> underlying(a: IC<T>): T = bar(a) {
|
||||
fun <T: Any> underlying(a: IC<T>): T? = bar(a) {
|
||||
it.value
|
||||
}
|
||||
|
||||
fun <T> extension(a: IC<T>): T = bar(a) {
|
||||
fun <T: Any> extension(a: IC<T>): T? = bar(a) {
|
||||
it.extensionValue()
|
||||
}
|
||||
|
||||
fun <T> dispatch(a: IC<T>): T = bar(a) {
|
||||
fun <T: Any> dispatch(a: IC<T>): T? = bar(a) {
|
||||
it.dispatchValue()
|
||||
}
|
||||
|
||||
fun <T> normal(a: IC<T>): T = bar(a) {
|
||||
fun <T: Any> normal(a: IC<T>): T? = bar(a) {
|
||||
normalValue(it)
|
||||
}
|
||||
|
||||
@@ -23,26 +23,26 @@ fun <T, R> bar(value: T, f: (T) -> R): R {
|
||||
return f(value)
|
||||
}
|
||||
|
||||
fun <T> IC<T>.extensionValue(): T = value
|
||||
fun <T: Any> IC<T>.extensionValue(): T? = value
|
||||
|
||||
fun <T> normalValue(ic: IC<T>): T = ic.value
|
||||
fun <T: Any> normalValue(ic: IC<T>): T? = ic.value
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IC<T>(val value: T) {
|
||||
fun dispatchValue(): T = value
|
||||
value class IC<T: Any>(val value: T?) {
|
||||
fun dispatchValue(): T? = value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var res = underlying<Int>(IC(40)) + 2
|
||||
var res = underlying<Int>(IC(40))!! + 2
|
||||
if (res != 42) "FAIL 1 $res"
|
||||
|
||||
res = extension<Int>(IC(40)) + 3
|
||||
res = extension<Int>(IC(40))!! + 3
|
||||
if (res != 43) return "FAIL 2: $res"
|
||||
|
||||
res = dispatch<Int>(IC(40)) + 4
|
||||
res = dispatch<Int>(IC(40))!! + 4
|
||||
if (res != 44) return "FAIL 3: $res"
|
||||
|
||||
res = normal<Int>(IC(40)) + 5
|
||||
res = normal<Int>(IC(40))!! + 5
|
||||
if (res != 45) return "FAIL 4: $res"
|
||||
|
||||
return "OK"
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// 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"
|
||||
}
|
||||
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
fun <T> underlying(a: IC<T>): T = bar(a, object : IFace<IC<T>, T> {
|
||||
override fun call(ic: IC<T>): T = ic.value
|
||||
})
|
||||
|
||||
fun <T> extension(a: IC<T>): T = bar(a, object : IFace<IC<T>, T> {
|
||||
override fun call(ic: IC<T>): T = ic.extensionValue()
|
||||
})
|
||||
|
||||
fun <T> dispatch(a: IC<T>): T = bar(a, object : IFace<IC<T>, T> {
|
||||
override fun call(ic: IC<T>): T = ic.dispatchValue()
|
||||
})
|
||||
|
||||
fun <T> normal(a: IC<T>): T = bar(a, object : IFace<IC<T>, T> {
|
||||
override fun call(ic: IC<T>): T = normalValue(ic)
|
||||
})
|
||||
|
||||
interface IFace<T, R> {
|
||||
fun call(ic: T): R
|
||||
}
|
||||
|
||||
fun <T, R> bar(value: T, f: IFace<T, R>): R {
|
||||
return f.call(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"
|
||||
}
|
||||
+7
@@ -3,6 +3,7 @@
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
class BoxT<T>(val boxed: T)
|
||||
class BoxT2<T: Any>(val boxed: T?)
|
||||
class BoxAny(val boxed: Any?)
|
||||
class BoxFoo(val boxed: IFoo?)
|
||||
|
||||
@@ -18,14 +19,17 @@ OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class StrArr(val value: Array<String>): IFoo
|
||||
|
||||
fun <T: String> boxToTypeParameter(x: Str<T>?) = BoxT(x)
|
||||
fun <T: String> boxToTypeParameter2(x: Str<T>?) = BoxT2(x)
|
||||
fun <T: String> boxToNullableAny(x: Str<T>?) = BoxAny(x)
|
||||
fun <T: String> boxToNullableInterface(x: Str<T>?) = BoxFoo(x)
|
||||
|
||||
fun <T: Str<String>> box2ToTypeParameter(x: Str2<T>?) = BoxT(x)
|
||||
fun <T: Str<String>> box2ToTypeParameter2(x: Str2<T>?) = BoxT2(x)
|
||||
fun <T: Str<String>> box2ToNullableAny(x: Str2<T>?) = BoxAny(x)
|
||||
fun <T: Str<String>> box2ToNullableInterface(x: Str2<T>?) = BoxFoo(x)
|
||||
|
||||
fun boxArrToTypeParameter(x: StrArr?) = BoxT(x)
|
||||
fun boxArrToTypeParameter2(x: StrArr?) = BoxT2(x)
|
||||
fun boxArrToNullableAny(x: StrArr?) = BoxAny(x)
|
||||
fun boxArrToNullableInterface(x: StrArr?) = BoxFoo(x)
|
||||
|
||||
@@ -43,14 +47,17 @@ fun useNullableStrArr(x: StrArr?) {
|
||||
|
||||
fun box(): String {
|
||||
useNullableStr(boxToTypeParameter<String>(null).boxed)
|
||||
useNullableStr(boxToTypeParameter2<String>(null).boxed)
|
||||
useNullableStr(boxToNullableAny<String>(null).boxed as Str<String>?)
|
||||
useNullableStr(boxToNullableInterface<String>(null).boxed as Str<String>?)
|
||||
|
||||
useNullableStr2(box2ToTypeParameter<Str<String>>(null).boxed)
|
||||
useNullableStr2(box2ToTypeParameter2<Str<String>>(null).boxed)
|
||||
useNullableStr2(box2ToNullableAny<Str<String>>(null).boxed as Str2<Str<String>>?)
|
||||
useNullableStr2(box2ToNullableInterface<Str<String>>(null).boxed as Str2<Str<String>>?)
|
||||
|
||||
useNullableStrArr(boxArrToTypeParameter(null).boxed)
|
||||
useNullableStrArr(boxArrToTypeParameter2(null).boxed)
|
||||
useNullableStrArr(boxArrToNullableAny(null).boxed as StrArr?)
|
||||
useNullableStrArr(boxArrToNullableInterface(null).boxed as StrArr?)
|
||||
|
||||
|
||||
-1
@@ -1,6 +1,5 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
class BoxT<T>(val boxed: T)
|
||||
|
||||
+3
-1
@@ -1,9 +1,9 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
class BoxT<T>(val boxed: T)
|
||||
class BoxT2<T: Any>(val boxed: T?)
|
||||
class BoxAny(val boxed: Any?)
|
||||
class BoxFoo(val boxed: IFoo?)
|
||||
|
||||
@@ -18,6 +18,7 @@ OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class I32<T: IcInt>(val value: T?) : IFoo where T: Marker
|
||||
|
||||
fun <T: IcInt> boxToTypeParameter(x: I32<T>?) where T: Marker = BoxT(x)
|
||||
fun <T: IcInt> boxToTypeParameter2(x: I32<T>?) where T: Marker = BoxT2(x)
|
||||
fun <T: IcInt> boxToNullableAny(x: I32<T>?) where T: Marker = BoxAny(x)
|
||||
fun <T: IcInt> boxToNullableInterface(x: I32<T>?) where T: Marker = BoxFoo(x)
|
||||
|
||||
@@ -27,6 +28,7 @@ fun <T: IcInt> useNullableI32(x: I32<T>?) where T: Marker {
|
||||
|
||||
fun box(): String {
|
||||
useNullableI32(boxToTypeParameter<IcInt>(null).boxed)
|
||||
useNullableI32(boxToTypeParameter2<IcInt>(null).boxed)
|
||||
useNullableI32(boxToNullableAny<IcInt>(null).boxed as I32<IcInt>?)
|
||||
useNullableI32(boxToNullableInterface<IcInt>(null).boxed as I32<IcInt>?)
|
||||
|
||||
|
||||
-1
@@ -1,6 +1,5 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
class BoxT<T>(val boxed: T)
|
||||
|
||||
+3
-2
@@ -1,9 +1,9 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
class BoxT<T>(val boxed: T)
|
||||
class BoxT2<T: Any>(val boxed: T?)
|
||||
class BoxAny(val boxed: Any?)
|
||||
class BoxFoo(val boxed: IFoo?)
|
||||
|
||||
@@ -13,6 +13,7 @@ OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class I32<T: Comparable<Int>>(val value: T?) : IFoo where T: Int
|
||||
|
||||
fun <T: Comparable<Int>> boxToTypeParameter(x: I32<T>?) where T: Int = BoxT(x)
|
||||
fun <T: Comparable<Int>> boxToTypeParameter2(x: I32<T>?) where T: Int = BoxT2(x)
|
||||
fun <T: Comparable<Int>> boxToNullableAny(x: I32<T>?) where T: Int = BoxAny(x)
|
||||
fun <T: Comparable<Int>> boxToNullableInterface(x: I32<T>?) where T: Int = BoxFoo(x)
|
||||
|
||||
@@ -21,7 +22,7 @@ fun <T: Comparable<Int>> useNullableI32(x: I32<T>?) where T: Int {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
useNullableI32(boxToTypeParameter<Int>(null).boxed)
|
||||
useNullableI32(boxToTypeParameter2<Int>(null).boxed)
|
||||
useNullableI32(boxToNullableAny<Int>(null).boxed as I32<Int>?)
|
||||
useNullableI32(boxToNullableInterface<Int>(null).boxed as I32<Int>?)
|
||||
|
||||
|
||||
+3
-1
@@ -1,9 +1,9 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// IGNORE_BACKEND: JVM
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
class BoxT<T>(val boxed: T)
|
||||
class BoxT2<T: Any>(val boxed: T?)
|
||||
class BoxAny(val boxed: Any?)
|
||||
class BoxFoo(val boxed: IFoo?)
|
||||
|
||||
@@ -13,6 +13,7 @@ OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class I32<T: Int>(val value: T?) : IFoo
|
||||
|
||||
fun <T: Int> boxToTypeParameter(x: I32<T>?) = BoxT(x)
|
||||
fun <T: Int> boxToTypeParameter2(x: I32<T>?) = BoxT2(x)
|
||||
fun <T: Int> boxToNullableAny(x: I32<T>?) = BoxAny(x)
|
||||
fun <T: Int> boxToNullableInterface(x: I32<T>?) = BoxFoo(x)
|
||||
|
||||
@@ -22,6 +23,7 @@ fun <T: Int> useNullableI32(x: I32<T>?) {
|
||||
|
||||
fun box(): String {
|
||||
useNullableI32(boxToTypeParameter<Int>(null).boxed)
|
||||
useNullableI32(boxToTypeParameter2<Int>(null).boxed)
|
||||
useNullableI32(boxToNullableAny<Int>(null).boxed as I32<Int>?)
|
||||
useNullableI32(boxToNullableInterface<Int>(null).boxed as I32<Int>?)
|
||||
|
||||
|
||||
+3
@@ -3,6 +3,7 @@
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
class BoxT<T>(val boxed: T)
|
||||
class BoxT2<T: Any>(val boxed: T?)
|
||||
class BoxAny(val boxed: Any?)
|
||||
class BoxFoo(val boxed: IFoo?)
|
||||
|
||||
@@ -12,6 +13,7 @@ OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class I32<T: Int>(val value: T) : IFoo
|
||||
|
||||
fun <T: Int> boxToTypeParameter(x: I32<T>?) = BoxT(x)
|
||||
fun <T: Int> boxToTypeParameter2(x: I32<T>?) = BoxT2(x)
|
||||
fun <T: Int> boxToNullableAny(x: I32<T>?) = BoxAny(x)
|
||||
fun <T: Int> boxToNullableInterface(x: I32<T>?) = BoxFoo(x)
|
||||
|
||||
@@ -21,6 +23,7 @@ fun <T: Int> useNullableI32(x: I32<T>?) {
|
||||
|
||||
fun box(): String {
|
||||
useNullableI32(boxToTypeParameter<Int>(null).boxed)
|
||||
useNullableI32(boxToTypeParameter2<Int>(null).boxed)
|
||||
useNullableI32(boxToNullableAny<Int>(null).boxed as I32<Int>?)
|
||||
useNullableI32(boxToNullableInterface<Int>(null).boxed as I32<Int>?)
|
||||
|
||||
|
||||
Vendored
+34
-1
@@ -16,6 +16,11 @@ value class BoxAny<T>(val value: T) {
|
||||
val intValue: Int get() = value as Int
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class BoxAny2<T: Any>(val value: T?) {
|
||||
val intValue: Int get() = value as Int
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class BoxInt<T: Int>(val value: T)
|
||||
|
||||
@@ -39,6 +44,16 @@ suspend fun <T> fooReceiver(block: suspend BoxAny<T>.() -> Unit) {
|
||||
block.startCoroutineUninterceptedOrReturn(BoxAny<T>(1 as T), EmptyContinuation())
|
||||
}
|
||||
|
||||
suspend fun <T: Any> foo2(block: suspend (BoxAny2<T>) -> Unit) {
|
||||
block(BoxAny2<T>(11 as T))
|
||||
block.startCoroutineUninterceptedOrReturn(BoxAny2<T>(1 as T), EmptyContinuation())
|
||||
}
|
||||
|
||||
suspend fun <T: Any> fooReceiver2(block: suspend BoxAny2<T>.() -> Unit) {
|
||||
BoxAny2<T>(11 as T).block()
|
||||
block.startCoroutineUninterceptedOrReturn(BoxAny2<T>(1 as T), EmptyContinuation())
|
||||
}
|
||||
|
||||
suspend fun <T: Int> bar(block: suspend (BoxInt<T>) -> Unit) {
|
||||
block(BoxInt<T>(2 as T))
|
||||
block.startCoroutineUninterceptedOrReturn(BoxInt<T>(2 as T), EmptyContinuation())
|
||||
@@ -66,6 +81,13 @@ suspend fun <T> BoxAny<T>.extension(block: suspend BoxAny<T>.() -> Unit) {
|
||||
block.startCoroutineUninterceptedOrReturn(this, EmptyContinuation())
|
||||
}
|
||||
|
||||
suspend fun <T: Any> BoxAny2<T>.extension(block: suspend BoxAny2<T>.() -> Unit) {
|
||||
this.block()
|
||||
block()
|
||||
|
||||
block.startCoroutineUninterceptedOrReturn(this, EmptyContinuation())
|
||||
}
|
||||
|
||||
suspend fun <T: Int> BoxInt<T>.extension(block: suspend BoxInt<T>.() -> Unit) {
|
||||
this.block()
|
||||
block()
|
||||
@@ -100,6 +122,12 @@ fun box(): String {
|
||||
fooReceiver<Int> {
|
||||
result += this.intValue
|
||||
}
|
||||
foo2<Int> { boxAny2 ->
|
||||
result += boxAny2.intValue
|
||||
}
|
||||
fooReceiver2<Int> {
|
||||
result += this.intValue
|
||||
}
|
||||
|
||||
bar<Int> { boxInt ->
|
||||
result += boxInt.value
|
||||
@@ -120,6 +148,11 @@ fun box(): String {
|
||||
result += intValue
|
||||
}
|
||||
|
||||
val b2 = BoxAny2(42)
|
||||
b2.extension {
|
||||
result += intValue
|
||||
}
|
||||
|
||||
val bInt = BoxInt(5)
|
||||
BoxInt(5).extension {
|
||||
result += value + bInt.value
|
||||
@@ -130,5 +163,5 @@ fun box(): String {
|
||||
}
|
||||
}
|
||||
|
||||
return if (result == 168) "OK" else "Error: $result"
|
||||
return if (result == 468) "OK" else "Error: $result"
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class NullableInt<T: Any>(private val holder: T?) {
|
||||
val intValue: Int get() = holder as Int
|
||||
}
|
||||
|
||||
val prop: ArrayList<NullableInt<Any>> = arrayListOf(NullableInt(0))
|
||||
|
||||
fun box(): String {
|
||||
val a = prop[0].intValue
|
||||
if (a != 0) return "Error 1: $a"
|
||||
|
||||
val local = mutableListOf(NullableInt(1))
|
||||
val b = local[0].intValue
|
||||
if (b != 1) return "Error 2: $b"
|
||||
|
||||
prop[0] = NullableInt(2)
|
||||
if (prop[0].intValue != 2) return "Error 3: ${prop[0].intValue}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user