KT-51290 Account for context receivers when generating delegate function bodies
This commit is contained in:
committed by
Space Team
parent
08767d572b
commit
1a76804862
@@ -0,0 +1,40 @@
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
data class Language(var name: String)
|
||||
|
||||
interface LoggingContext {
|
||||
fun log(level: Int, message: String)
|
||||
}
|
||||
|
||||
interface SaveRepository<T> {
|
||||
context(LoggingContext)
|
||||
fun save(content: T)
|
||||
}
|
||||
|
||||
context(LoggingContext, SaveRepository<Language>)
|
||||
fun startBusinessOperation() {
|
||||
log(0, "Operation has started")
|
||||
save(Language("Kotlin"))
|
||||
}
|
||||
|
||||
class CompositeContext(c1: LoggingContext, c2: SaveRepository<Language>): LoggingContext by c1, SaveRepository<Language> by c2
|
||||
|
||||
fun box(): String {
|
||||
val loggingCtx = object : LoggingContext {
|
||||
override fun log(level: Int, message: String) {}
|
||||
}
|
||||
|
||||
val saveCtx = object : SaveRepository<Language> {
|
||||
context(LoggingContext)
|
||||
override fun save(content: Language) {
|
||||
log(message = "Saving $content", level = 123)
|
||||
}
|
||||
}
|
||||
|
||||
with(CompositeContext(loggingCtx, saveCtx)) {
|
||||
startBusinessOperation()
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user