[tests] BI (1P&1TV/1TIO): add tests for target types

single builder parameter
single postponed type variable
single origin of type information

relevant issues:
KT-60719
KT-60720
KT-60855
KT-60877
KT-60880
This commit is contained in:
Stanislav Ruban
2023-08-02 11:53:42 +03:00
committed by Space Team
parent bfe54942d3
commit 44a4c4ee1c
64 changed files with 6518 additions and 0 deletions
@@ -0,0 +1,115 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = reference as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
private var reference: Any? = null
val <T> Buildee<T>.typeArgumentValue: T get() = reference as T
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testAnonymousObjectOutsideBuilderArgument() {
val obj = object {}
reference = obj
val buildee = build {
yield(obj)
}
checkTypeEquality(obj, buildee.typeArgumentValue)
}
fun testAnonymousObjectInsideBuilderArgument() {
val buildee = build {
val obj = object { fun anonOnlyFunc() {} }
reference = obj
yield(obj)
}
buildee.typeArgumentValue.anonOnlyFunc()
}
fun testThisExpression() {
val buildee = build {
val obj = object {
fun anonOnlyFunc() {}
fun initialize() {
reference = this
yield(this)
}
}
obj.initialize()
}
buildee.typeArgumentValue.anonOnlyFunc()
}
testAnonymousObjectOutsideBuilderArgument()
testAnonymousObjectInsideBuilderArgument()
testThisExpression()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testAnonymousObjectOutsideBuilderArgument() {
val obj = object {}
reference = obj
val buildee = build {
fun <T> shareTypeInfo(from: T, to: T) {}
shareTypeInfo(obj, materialize())
}
checkTypeEquality(obj, buildee.typeArgumentValue)
}
fun testAnonymousObjectInsideBuilderArgument() {
val buildee = build {
val obj = object { fun anonOnlyFunc() {} }
reference = obj
fun <T> shareTypeInfo(from: T, to: T) {}
shareTypeInfo(obj, materialize())
}
buildee.typeArgumentValue.anonOnlyFunc()
}
fun testThisExpression() {
val buildee = build {
val obj = object {
fun anonOnlyFunc() {}
fun initialize() {
reference = this
fun <T> shareTypeInfo(from: T, to: T) {}
shareTypeInfo(this, materialize())
}
}
obj.initialize()
}
buildee.typeArgumentValue.anonOnlyFunc()
}
testAnonymousObjectOutsideBuilderArgument()
testAnonymousObjectInsideBuilderArgument()
testThisExpression()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,47 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
class Context<T> {
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: T & Any = UserKlass() as (T & Any)
val buildee = build {
yield(arg)
}
checkExactType<Buildee<T & Any>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: T & Any) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<T & Any>>(buildee)
}
}
fun box(): String {
with(Context<UserKlass?>()) {
testYield()
testMaterialize()
}
return "OK"
}
@@ -0,0 +1,70 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass {
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: UserKlass = UserKlass()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass>>(buildee)
}
fun testThisExpression() {
val buildee = build {
yield(this@UserKlass)
}
checkExactType<Buildee<UserKlass>>(buildee)
}
testBasicCase()
testThisExpression()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: UserKlass) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass>>(buildee)
}
fun testThisExpression() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(this@UserKlass, materialize())
}
checkExactType<Buildee<UserKlass>>(buildee)
}
testBasicCase()
testThisExpression()
}
}
fun box(): String {
with(UserKlass()) {
testYield()
testMaterialize()
}
return "OK"
}
@@ -0,0 +1,52 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = reference as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
private var reference: Any? = null
val <T> Buildee<T>.typeArgumentValue: T get() = reference as T
enum class UserEnumeration {
ENUM_ENTRY {
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val buildee = build {
yield(this@ENUM_ENTRY)
}
checkTypeEquality(this@ENUM_ENTRY, buildee.typeArgumentValue)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
val buildee = build {
fun <T> shareTypeInfo(from: T, to: T) {}
shareTypeInfo(this@ENUM_ENTRY, materialize())
}
checkTypeEquality(this@ENUM_ENTRY, buildee.typeArgumentValue)
}
init {
reference = this@ENUM_ENTRY
testYield()
testMaterialize()
}
};
}
fun box(): String {
UserEnumeration.ENUM_ENTRY
return "OK"
}
@@ -0,0 +1,72 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserEnumeration.ENUM_ENTRY as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
enum class UserEnumeration {
ENUM_ENTRY;
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: UserEnumeration = ENUM_ENTRY
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserEnumeration>>(buildee)
}
fun testThisExpression() {
val buildee = build {
yield(this@UserEnumeration)
}
checkExactType<Buildee<UserEnumeration>>(buildee)
}
testBasicCase()
testThisExpression()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: UserEnumeration) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserEnumeration>>(buildee)
}
fun testThisExpression() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(this@UserEnumeration, materialize())
}
checkExactType<Buildee<UserEnumeration>>(buildee)
}
testBasicCase()
testThisExpression()
}
}
fun box(): String {
with(UserEnumeration.ENUM_ENTRY) {
testYield()
testMaterialize()
}
return "OK"
}
@@ -0,0 +1,74 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass().Inner<Placeholder>() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass {
inner class Inner<T> {
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: UserKlass.Inner<T> = UserKlass().Inner()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass.Inner<T>>>(buildee)
}
fun testThisExpression() {
val buildee = build {
yield(this@Inner)
}
checkExactType<Buildee<UserKlass.Inner<T>>>(buildee)
}
testBasicCase()
testThisExpression()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: UserKlass.Inner<T>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass.Inner<T>>>(buildee)
}
fun testThisExpression() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(this@Inner, materialize())
}
checkExactType<Buildee<UserKlass.Inner<T>>>(buildee)
}
testBasicCase()
testThisExpression()
}
}
}
class Placeholder
fun box(): String {
with(UserKlass().Inner<Placeholder>()) {
testYield()
testMaterialize()
}
return "OK"
}
@@ -0,0 +1,72 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass<Placeholder>() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass<T> {
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: UserKlass<T> = UserKlass()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass<T>>>(buildee)
}
fun testThisExpression() {
val buildee = build {
yield(this@UserKlass)
}
checkExactType<Buildee<UserKlass<T>>>(buildee)
}
testBasicCase()
testThisExpression()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: UserKlass<T>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass<T>>>(buildee)
}
fun testThisExpression() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(this@UserKlass, materialize())
}
checkExactType<Buildee<UserKlass<T>>>(buildee)
}
testBasicCase()
testThisExpression()
}
}
class Placeholder
fun box(): String {
with(UserKlass<Placeholder>()) {
testYield()
testMaterialize()
}
return "OK"
}
@@ -0,0 +1,74 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass<Placeholder>().Inner() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass<T> {
inner class Inner {
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: UserKlass<T>.Inner = UserKlass<T>().Inner()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass<T>.Inner>>(buildee)
}
fun testThisExpression() {
val buildee = build {
yield(this@Inner)
}
checkExactType<Buildee<UserKlass<T>.Inner>>(buildee)
}
testBasicCase()
testThisExpression()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: UserKlass<T>.Inner) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass<T>.Inner>>(buildee)
}
fun testThisExpression() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(this@Inner, materialize())
}
checkExactType<Buildee<UserKlass<T>.Inner>>(buildee)
}
testBasicCase()
testThisExpression()
}
}
}
class Placeholder
fun box(): String {
with(UserKlass<Placeholder>().Inner()) {
testYield()
testMaterialize()
}
return "OK"
}
@@ -0,0 +1,72 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass().Inner() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass {
inner class Inner {
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: UserKlass.Inner = UserKlass().Inner()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass.Inner>>(buildee)
}
fun testThisExpression() {
val buildee = build {
yield(this@Inner)
}
checkExactType<Buildee<UserKlass.Inner>>(buildee)
}
testBasicCase()
testThisExpression()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: UserKlass.Inner) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass.Inner>>(buildee)
}
fun testThisExpression() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(this@Inner, materialize())
}
checkExactType<Buildee<UserKlass.Inner>>(buildee)
}
testBasicCase()
testThisExpression()
}
}
}
fun box(): String {
with(UserKlass().Inner()) {
testYield()
testMaterialize()
}
return "OK"
}
@@ -0,0 +1,70 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserEnumeration.ENUM_ENTRY as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
enum class UserEnumeration {
ENUM_ENTRY
}
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: UserEnumeration = UserEnumeration.ENUM_ENTRY
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserEnumeration>>(buildee)
}
fun testEnumEntry() {
val buildee = build {
yield(UserEnumeration.ENUM_ENTRY)
}
checkExactType<Buildee<UserEnumeration>>(buildee)
}
testBasicCase()
testEnumEntry()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: UserEnumeration) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserEnumeration>>(buildee)
}
fun testEnumEntry() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(UserEnumeration.ENUM_ENTRY, materialize())
}
checkExactType<Buildee<UserEnumeration>>(buildee)
}
testBasicCase()
testEnumEntry()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,46 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass().Inner<Placeholder>() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass {
inner class Inner<T>
}
class Placeholder
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass.Inner<Placeholder> = UserKlass().Inner()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass.Inner<Placeholder>>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass.Inner<Placeholder>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass.Inner<Placeholder>>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,91 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = { _: UserKlass -> } as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: (UserKlass) -> Unit = { _: UserKlass -> }
val buildee = build {
yield(arg)
}
checkExactType<Buildee<(UserKlass) -> Unit>>(buildee)
}
fun testExplicitlyUnaryLiterals() {
fun test1() {
val buildee = build {
yield { _: UserKlass -> }
}
checkExactType<Buildee<(UserKlass) -> Unit>>(buildee)
}
fun test2() {
val buildee = build {
yield(fun(_: UserKlass) {})
}
checkExactType<Buildee<(UserKlass) -> Unit>>(buildee)
}
test1()
test2()
}
testBasicCase()
testExplicitlyUnaryLiterals()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: (UserKlass) -> Unit) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<(UserKlass) -> Unit>>(buildee)
}
fun testExplicitlyUnaryLiterals() {
fun test1() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo({ _: UserKlass -> }, materialize())
}
checkExactType<Buildee<(UserKlass) -> Unit>>(buildee)
}
fun test2() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(fun(_: UserKlass) {}, materialize())
}
checkExactType<Buildee<(UserKlass) -> Unit>>(buildee)
}
test1()
test2()
}
testBasicCase()
testExplicitlyUnaryLiterals()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,68 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = fun UserKlass.() {} as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: UserKlass.() -> Unit = fun UserKlass.() {}
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass.() -> Unit>>(buildee)
}
fun testLiteralWithExplicitlyPresentReceiver() {
val buildee = build {
yield(fun UserKlass.() {})
}
checkExactType<Buildee<UserKlass.() -> Unit>>(buildee)
}
testBasicCase()
testLiteralWithExplicitlyPresentReceiver()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: UserKlass.() -> Unit) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass.() -> Unit>>(buildee)
}
fun testLiteralWithExplicitlyPresentReceiver() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(fun UserKlass.() {}, materialize())
}
checkExactType<Buildee<UserKlass.() -> Unit>>(buildee)
}
testBasicCase()
testLiteralWithExplicitlyPresentReceiver()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,124 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = reference as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
private var reference: Any? = null
val <T> Buildee<T>.typeArgumentValue: T get() = reference as T
class UserKlass
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testLocalClassOutsideBuilderArgument() {
class Local<T>
reference = Local<UserKlass>()
val arg: Local<UserKlass> = Local()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<Local<UserKlass>>>(buildee)
}
fun testLocalClassInsideBuilderArgument() {
val buildee = build {
class Local<T> { fun localOnlyFunc(): T = UserKlass() as T }
reference = Local<UserKlass>()
val arg: Local<UserKlass> = Local()
yield(arg)
}
val result = buildee.typeArgumentValue.localOnlyFunc()
checkExactType<UserKlass>(result)
}
fun testTypeInfoOriginInsideLocalClass() {
val buildee = build {
class Local<T> {
fun localOnlyFunc(): T = UserKlass() as T
fun initialize() {
reference = Local<UserKlass>()
val arg: Local<UserKlass> = Local()
yield(arg)
}
}
Local<UserKlass>().initialize()
}
val result = buildee.typeArgumentValue.localOnlyFunc()
checkExactType<UserKlass>(result)
}
testLocalClassOutsideBuilderArgument()
testLocalClassInsideBuilderArgument()
testTypeInfoOriginInsideLocalClass()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testLocalClassOutsideBuilderArgument() {
class Local<T>
reference = Local<UserKlass>()
fun consume(arg: Local<UserKlass>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<Local<UserKlass>>>(buildee)
}
fun testLocalClassInsideBuilderArgument() {
val buildee = build {
class Local<T> { fun localOnlyFunc(): T = UserKlass() as T }
reference = Local<UserKlass>()
fun consume(arg: Local<UserKlass>) {}
consume(materialize())
}
val result = buildee.typeArgumentValue.localOnlyFunc()
checkExactType<UserKlass>(result)
}
fun testTypeInfoOriginInsideLocalClass() {
val buildee = build {
class Local<T> {
fun localOnlyFunc(): T = UserKlass() as T
fun initialize() {
reference = Local<UserKlass>()
fun consume(arg: Local<UserKlass>) {}
consume(materialize())
}
}
Local<UserKlass>().initialize()
}
val result = buildee.typeArgumentValue.localOnlyFunc()
checkExactType<UserKlass>(result)
}
testLocalClassOutsideBuilderArgument()
testLocalClassInsideBuilderArgument()
testTypeInfoOriginInsideLocalClass()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,119 @@
// IGNORE_BACKEND: JVM
/* ^ code compiled by legacy JVM backend fails in run-time with
* NoSuchMethodError: GenericLocalClassWithLeakingTypeParameterKt$testYield$1$buildee$1$Local: method <init>()V not found
*/
// ISSUE: KT-60855
/* ATTENTION:
* this test monitors an unfixed compiler bug;
* if the behavior of the test changes, please consult with the linked YT ticket
* to check whether the described problem has been fixed by your changes;
* if the issue isn't actually fixed but new behavior persists,
* please add a comment about the behavior change to the ticket
* (preferably accompanied by an analysis of the change's reasons)
*/
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = reference as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
private var reference: Any? = null
val <T> Buildee<T>.typeArgumentValue: T get() = reference as T
class UserKlass
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testTypeInfoOriginInsideLocalClass() {
val buildee = build {
class Local<T> {
fun localOnlyFunc(): T = UserKlass() as T
fun initialize() {
reference = Local<T>()
val arg: Local<T> = Local()
yield(arg)
}
}
Local<UserKlass>().initialize()
}
val result = buildee.typeArgumentValue.localOnlyFunc()
<!DEBUG_INFO_EXPRESSION_TYPE("T")!>result<!>
}
fun testThisExpression() {
val buildee = build {
class Local<T> {
fun localOnlyFunc(): T = UserKlass() as T
fun initialize() {
reference = this
yield(this)
}
}
Local<UserKlass>().initialize()
}
val result = buildee.typeArgumentValue.localOnlyFunc()
<!DEBUG_INFO_EXPRESSION_TYPE("T")!>result<!>
}
testTypeInfoOriginInsideLocalClass()
testThisExpression()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testTypeInfoOriginInsideLocalClass() {
val buildee = build {
class Local<T> {
fun localOnlyFunc(): T = UserKlass() as T
fun initialize() {
reference = Local<T>()
fun consume(arg: Local<T>) {}
consume(materialize())
}
}
Local<UserKlass>().initialize()
}
val result = buildee.typeArgumentValue.localOnlyFunc()
<!DEBUG_INFO_EXPRESSION_TYPE("T")!>result<!>
}
fun testThisExpression() {
val buildee = build {
class Local<T> {
fun localOnlyFunc(): T = UserKlass() as T
fun initialize() {
reference = this
fun <T> shareTypeInfo(from: T, to: T) {}
shareTypeInfo(this, materialize())
}
}
Local<UserKlass>().initialize()
}
val result = buildee.typeArgumentValue.localOnlyFunc()
<!DEBUG_INFO_EXPRESSION_TYPE("T")!>result<!>
}
testTypeInfoOriginInsideLocalClass()
testThisExpression()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,45 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = In<UserSuperklass>() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class In<in T>
open class UserSuperklass
open class UserKlass: UserSuperklass()
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: In<UserKlass> = In<UserSuperklass>()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<In<UserKlass>>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: In<UserKlass>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<In<UserKlass>>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,45 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = Out<UserSubklass>() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class Out<out T>
open class UserKlass
open class UserSubklass: UserKlass()
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: Out<UserKlass> = Out<UserSubklass>()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<Out<UserKlass>>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Out<UserKlass>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<Out<UserKlass>>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,45 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = Inv<UserSuperklass>() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class Inv<T>
open class UserSuperklass
open class UserKlass: UserSuperklass()
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: Inv<in UserKlass> = Inv<UserSuperklass>()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<Inv<in UserKlass>>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Inv<in UserKlass>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<Inv<in UserKlass>>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,44 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = Inv<UserKlass>() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class Inv<T>
class UserKlass
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: Inv<UserKlass> = Inv()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<Inv<UserKlass>>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Inv<UserKlass>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<Inv<UserKlass>>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,45 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = Inv<UserSubklass>() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class Inv<T>
open class UserKlass
open class UserSubklass: UserKlass()
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: Inv<out UserKlass> = Inv<UserSubklass>()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<Inv<out UserKlass>>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Inv<out UserKlass>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<Inv<out UserKlass>>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,43 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = Inv<Any?>() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class Inv<T>
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: Inv<*> = Inv<Any?>()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<Inv<*>>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Inv<*>) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<Inv<*>>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,46 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass<Placeholder>().Inner() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass<T> {
inner class Inner
}
class Placeholder
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass<Placeholder>.Inner = UserKlass<Placeholder>().Inner()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass<Placeholder>.Inner>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass<Placeholder>.Inner) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass<Placeholder>.Inner>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,45 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass().Inner() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass {
inner class Inner
}
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass.Inner = UserKlass().Inner()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass.Inner>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass.Inner) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass.Inner>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,104 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = 42 as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: Int = 42
val buildee = build {
yield(arg)
}
checkExactType<Buildee<Int>>(buildee)
}
fun testLiterals() {
fun test1() {
val buildee = build {
yield(42)
}
checkExactType<Buildee<Int>>(buildee)
}
fun test2() {
val buildee = build {
yield(0x13)
}
checkExactType<Buildee<Int>>(buildee)
}
fun test3() {
val buildee = build {
yield(0b1000)
}
checkExactType<Buildee<Int>>(buildee)
}
test1()
test2()
test3()
}
testBasicCase()
testLiterals()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: Int) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<Int>>(buildee)
}
fun testLiterals() {
fun test1() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(42, materialize())
}
checkExactType<Buildee<Int>>(buildee)
}
fun test2() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(0x13, materialize())
}
checkExactType<Buildee<Int>>(buildee)
}
fun test3() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(0b1000, materialize())
}
checkExactType<Buildee<Int>>(buildee)
}
test1()
test2()
test3()
}
testBasicCase()
testLiterals()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,52 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = reference as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
private var reference: Any? = null
val <T> Buildee<T>.typeArgumentValue: T get() = reference as T
interface I1
interface I2
object A: I1, I2
object B: I1, I2
fun <T> select(vararg arg: T): T = arg[0]
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val intersection = select(A, B)
val buildee = build {
yield(intersection)
}
checkTypeEquality(intersection, buildee.typeArgumentValue)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
val intersection = select(A, B)
val buildee = build {
fun <T> shareTypeInfo(from: T, to: T) {}
shareTypeInfo(intersection, materialize())
}
checkTypeEquality(intersection, buildee.typeArgumentValue)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,153 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = reference as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
private var reference: Any? = null
val <T> Buildee<T>.typeArgumentValue: T get() = reference as T
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testLocalClassOutsideBuilderArgument() {
class Local
reference = Local()
val arg: Local = Local()
val buildee = build {
yield(arg)
}
checkExactType<Buildee<Local>>(buildee)
}
fun testLocalClassInsideBuilderArgument() {
val buildee = build {
class Local { fun localOnlyFunc() {} }
reference = Local()
val arg: Local = Local()
yield(arg)
}
buildee.typeArgumentValue.localOnlyFunc()
}
fun testTypeInfoOriginInsideLocalClass() {
val buildee = build {
class Local {
fun localOnlyFunc() {}
fun initialize() {
reference = Local()
val arg: Local = Local()
yield(arg)
}
}
Local().initialize()
}
buildee.typeArgumentValue.localOnlyFunc()
}
fun testThisExpression() {
val buildee = build {
class Local {
fun localOnlyFunc() {}
fun initialize() {
reference = this
yield(this)
}
}
Local().initialize()
}
buildee.typeArgumentValue.localOnlyFunc()
}
testLocalClassOutsideBuilderArgument()
testLocalClassInsideBuilderArgument()
testTypeInfoOriginInsideLocalClass()
testThisExpression()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testLocalClassOutsideBuilderArgument() {
class Local
reference = Local()
fun consume(arg: Local) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<Local>>(buildee)
}
fun testLocalClassInsideBuilderArgument() {
val buildee = build {
class Local { fun localOnlyFunc() {} }
reference = Local()
fun consume(arg: Local) {}
consume(materialize())
}
buildee.typeArgumentValue.localOnlyFunc()
}
fun testTypeInfoOriginInsideLocalClass() {
val buildee = build {
class Local {
fun localOnlyFunc() {}
fun initialize() {
reference = Local()
fun consume(arg: Local) {}
consume(materialize())
}
}
Local().initialize()
}
buildee.typeArgumentValue.localOnlyFunc()
}
fun testThisExpression() {
val buildee = build {
class Local {
fun localOnlyFunc() {}
fun initialize() {
reference = this
fun <T> shareTypeInfo(from: T, to: T) {}
shareTypeInfo(this, materialize())
}
}
Local().initialize()
}
buildee.typeArgumentValue.localOnlyFunc()
}
testLocalClassOutsideBuilderArgument()
testLocalClassInsideBuilderArgument()
testTypeInfoOriginInsideLocalClass()
testThisExpression()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,32 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
import kotlin.IllegalStateException
class Buildee<CT> {
fun yield(arg: CT) {}
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
fun testYield() {
val buildee = build {
try {
yield(throw IllegalStateException())
} catch (e: IllegalStateException) {}
}
checkExactType<Buildee<Nothing>>(buildee)
}
fun box(): String {
testYield()
return "OK"
}
@@ -0,0 +1,41 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = null as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: Nothing? = null
val buildee = build {
yield(arg)
}
checkExactType<Buildee<Nothing?>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Nothing?) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<Nothing?>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,28 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
fun testYield() {
val buildee = build {
yield(null)
}
checkExactType<Buildee<Nothing?>>(buildee)
}
fun box(): String {
testYield()
return "OK"
}
@@ -0,0 +1,43 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = null as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass? = null
val buildee = build {
yield(arg)
}
checkExactType<Buildee<UserKlass?>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass?) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<UserKlass?>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,47 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = null as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
class Context<T> {
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: T? = null
val buildee = build {
yield(arg)
}
checkExactType<Buildee<T?>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: T?) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<T?>>(buildee)
}
}
fun box(): String {
with(Context<UserKlass>()) {
testYield()
testMaterialize()
}
return "OK"
}
@@ -0,0 +1,104 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = { -> } as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: () -> Unit = { -> }
val buildee = build {
yield(arg)
}
checkExactType<Buildee<() -> Unit>>(buildee)
}
fun testLiterals() {
fun test1() {
val buildee = build {
yield { -> }
}
checkExactType<Buildee<() -> Unit>>(buildee)
}
fun test2() {
val buildee = build {
yield(fun() {})
}
checkExactType<Buildee<() -> Unit>>(buildee)
}
fun test3() {
val buildee = build {
yield {}
}
checkExactType<Buildee<() -> Unit>>(buildee)
}
test1()
test2()
test3()
}
testBasicCase()
testLiterals()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: () -> Unit) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<() -> Unit>>(buildee)
}
fun testLiterals() {
fun test1() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo({ -> }, materialize())
}
checkExactType<Buildee<() -> Unit>>(buildee)
}
fun test2() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(fun() {}, materialize())
}
checkExactType<Buildee<() -> Unit>>(buildee)
}
fun test3() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo({}, materialize())
}
checkExactType<Buildee<() -> Unit>>(buildee)
}
test1()
test2()
test3()
}
testBasicCase()
testLiterals()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,127 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = l@ { return@l UserKlass() } as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: () -> UserKlass = l@ { return@l UserKlass() }
val buildee = build {
yield(arg)
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
fun testLiterals() {
fun test1() {
val buildee = build {
yield { return@yield UserKlass() }
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
fun test2() {
val buildee = build {
yield(fun(): UserKlass { return UserKlass() })
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
fun test3() {
val buildee = build {
yield { UserKlass() }
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
fun test4() {
val buildee = build {
yield(fun() = UserKlass())
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
test1()
test2()
test3()
test4()
}
testBasicCase()
testLiterals()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: () -> UserKlass) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
fun testLiterals() {
fun test1() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(
{ return@shareTypeInfo UserKlass() },
materialize()
)
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
fun test2() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(
fun(): UserKlass { return UserKlass() },
materialize()
)
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
fun test3() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo({ UserKlass() }, materialize())
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
fun test4() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(fun() = UserKlass(), materialize())
}
checkExactType<Buildee<() -> UserKlass>>(buildee)
}
test1()
test2()
test3()
test4()
}
testBasicCase()
testLiterals()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,104 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = "42" as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: String = "42"
val buildee = build {
yield(arg)
}
checkExactType<Buildee<String>>(buildee)
}
fun testLiterals() {
fun test1() {
val buildee = build {
yield("42")
}
checkExactType<Buildee<String>>(buildee)
}
fun test2() {
val buildee = build {
yield("""42""")
}
checkExactType<Buildee<String>>(buildee)
}
fun test3() {
val buildee = build {
yield("${4}${2}")
}
checkExactType<Buildee<String>>(buildee)
}
test1()
test2()
test3()
}
testBasicCase()
testLiterals()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: String) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<String>>(buildee)
}
fun testLiterals() {
fun test1() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo("42", materialize())
}
checkExactType<Buildee<String>>(buildee)
}
fun test2() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo("""42""", materialize())
}
checkExactType<Buildee<String>>(buildee)
}
fun test3() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo("${4}${2}", materialize())
}
checkExactType<Buildee<String>>(buildee)
}
test1()
test2()
test3()
}
testBasicCase()
testLiterals()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,68 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
// WITH_STDLIB
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = suspend {} as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
fun testBasicCase() {
val arg: suspend () -> Unit = suspend {}
val buildee = build {
yield(arg)
}
checkExactType<Buildee<suspend () -> Unit>>(buildee)
}
fun testLiteral() {
val buildee = build {
yield(suspend {})
}
checkExactType<Buildee<suspend () -> Unit>>(buildee)
}
testBasicCase()
testLiteral()
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun testBasicCase() {
fun consume(arg: suspend () -> Unit) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<suspend () -> Unit>>(buildee)
}
fun testLiteral() {
fun <T> shareTypeInfo(from: T, to: T) {}
val buildee = build {
shareTypeInfo(suspend {}, materialize())
}
checkExactType<Buildee<suspend () -> Unit>>(buildee)
}
testBasicCase()
testLiteral()
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,47 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
class Context<T> {
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: T = UserKlass() as T
val buildee = build {
yield(arg)
}
checkExactType<Buildee<T>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: T) {}
val buildee = build {
consume(materialize())
}
checkExactType<Buildee<T>>(buildee)
}
}
fun box(): String {
with(Context<UserKlass>()) {
testYield()
testMaterialize()
}
return "OK"
}