// RUN_PIPELINE_TILL: FRONTEND
fun test() {
    val resultA = pcla { otvOwner ->
        otvOwner.constrain(ScopeOwner())
        // should fix OTv := ScopeOwner for scope navigation
        otvOwner.provide()::<!UNRESOLVED_REFERENCE!>InnerKlass<!>
        // expected: Interloper </: ScopeOwner
        otvOwner.constrain(Interloper)
    }
    // expected: ScopeOwner
    <!DEBUG_INFO_EXPRESSION_TYPE("BaseType")!>resultA<!>

    val resultB = pcla { otvOwner ->
        otvOwner.constrain(ScopeOwner())
        // should fix OTv := ScopeOwner for scope navigation
        otvOwner.provide()::<!UNRESOLVED_REFERENCE!>accessorBackedReadableProperty<!>
        // expected: Interloper </: ScopeOwner
        otvOwner.constrain(Interloper)
    }
    // expected: ScopeOwner
    <!DEBUG_INFO_EXPRESSION_TYPE("BaseType")!>resultB<!>

    val resultC = pcla { otvOwner ->
        otvOwner.constrain(ScopeOwner())
        // should fix OTv := ScopeOwner for scope navigation
        otvOwner.provide()::<!UNRESOLVED_REFERENCE!>accessorBackedWriteableProperty<!>
        // expected: Interloper </: ScopeOwner
        otvOwner.constrain(Interloper)
    }
    // expected: ScopeOwner
    <!DEBUG_INFO_EXPRESSION_TYPE("BaseType")!>resultC<!>

    val resultD = pcla { otvOwner ->
        otvOwner.constrain(ScopeOwner())
        // should fix OTv := ScopeOwner for scope navigation
        otvOwner.provide()::<!UNRESOLVED_REFERENCE!>delegatedReadableProperty<!>
        // expected: Interloper </: ScopeOwner
        otvOwner.constrain(Interloper)
    }
    // expected: ScopeOwner
    <!DEBUG_INFO_EXPRESSION_TYPE("BaseType")!>resultD<!>

    val resultE = pcla { otvOwner ->
        otvOwner.constrain(ScopeOwner())
        // should fix OTv := ScopeOwner for scope navigation
        otvOwner.provide()::<!UNRESOLVED_REFERENCE!>delegatedWriteableProperty<!>
        // expected: Interloper </: ScopeOwner
        otvOwner.constrain(Interloper)
    }
    // expected: ScopeOwner
    <!DEBUG_INFO_EXPRESSION_TYPE("BaseType")!>resultE<!>
}


class TypeVariableOwner<T> {
    fun constrain(subtypeValue: T) {}
    fun provide(): T = null!!
}

fun <OT> pcla(lambda: (TypeVariableOwner<OT>) -> Unit): OT = null!!

interface BaseType

object Value

class ScopeOwner: BaseType {
    inner class InnerKlass

    val accessorBackedReadableProperty: Value
        get() = Value

    var accessorBackedWriteableProperty: Value
        get() = Value
        set(value) {}

    operator fun getValue(reference: ScopeOwner, property: Any?): Value = Value
    operator fun setValue(reference: ScopeOwner, property: Any?, value: Value) {}

    val delegatedReadableProperty: Value by this
    var delegatedWriteableProperty: Value by this

    companion object {
        fun Nullable(): ScopeOwner? = null
    }
}

object Interloper: BaseType

/* GENERATED_FIR_TAGS: callableReference, checkNotNullCall, classDeclaration, companionObject, functionDeclaration,
functionalType, getter, inner, interfaceDeclaration, lambdaLiteral, localProperty, nullableType, objectDeclaration,
operator, propertyDeclaration, propertyDelegate, setter, thisExpression, typeParameter */
