You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
3 years ago
|
// @Module:Main
|
||
|
|
||
|
// https://youtrack.jetbrains.com/issue/KT-46880
|
||
|
import androidx.compose.runtime.Composable
|
||
|
|
||
|
fun main() {
|
||
3 years ago
|
var set = mutableSetOf<Int>()
|
||
|
|
||
|
val instance = testCase {
|
||
|
set.add(1)
|
||
|
}
|
||
3 years ago
|
val instance2 = TestCase2()
|
||
|
|
||
|
callComposable {
|
||
|
instance.composable()
|
||
|
instance2.composable()
|
||
3 years ago
|
set.add(2)
|
||
3 years ago
|
}
|
||
3 years ago
|
require(setOf(1, 2) == set) { "Failed when running composables" }
|
||
3 years ago
|
}
|
||
|
|
||
|
// @Module:Lib
|
||
|
import androidx.compose.runtime.Composable
|
||
|
import kotlin.properties.ReadOnlyProperty
|
||
|
import kotlin.reflect.KProperty
|
||
|
|
||
|
class TestCase(val composable: @Composable () -> Unit) {
|
||
|
operator fun provideDelegate(
|
||
|
thisRef: Any,
|
||
|
property: KProperty<*>
|
||
|
): ReadOnlyProperty<Any?, String> {
|
||
|
return ReadOnlyProperty { _, _ -> property.name }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class TestCase2(val composable: @Composable () -> Unit = {}) {
|
||
|
operator fun provideDelegate(
|
||
|
thisRef: Any,
|
||
|
property: KProperty<*>
|
||
|
): ReadOnlyProperty<Any?, String> {
|
||
|
return ReadOnlyProperty { _, _ -> property.name }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fun testCase(composable: @Composable () -> Unit): TestCase {
|
||
|
return TestCase(composable)
|
||
|
}
|