// RUN_PIPELINE_TILL: FRONTEND
// WITH_STDLIB
// SKIP_TXT
// DIAGNOSTICS: -CAST_NEVER_SUCCEEDS -UNCHECKED_CAST -UNUSED_PARAMETER -UNUSED_VARIABLE -OPT_IN_USAGE_ERROR -UNUSED_EXPRESSION

import kotlin.experimental.ExperimentalTypeInference

fun <K> K.bar3(): K = null as K
fun <K> K.foo3(): K = null as K

fun bar2(): Int = 1
fun foo2(): Float = 1f

fun <K> bar4(): K = null as K
fun <K> foo4(): K = null as K

class Foo6

class Foo7<T>
fun foo7() = null as Foo7<Int>

fun poll0(flag: Boolean) {
    val inv = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KFunction0<kotlin.Int>")!>if (flag) { ::bar2 } else { ::foo4 }<!>
    inv()
}

fun poll1(flag: Boolean) {
    val inv = if (flag) { ::bar2 } else { ::foo2 }
    inv()
}

fun poll11(flag: Boolean) {
    val inv = if (flag) { ::bar2 } else { ::foo2 }
    inv()
}

fun poll12(flag: Boolean) {
    val inv = if (flag) { ::<!UNRESOLVED_REFERENCE!>bar3<!> } else { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll13(flag: Boolean) {
    val inv = if (flag) { ::bar2 } else { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
    inv()
}

fun poll14(flag: Boolean) {
    val inv = if (flag) { ::<!CANNOT_INFER_PARAMETER_TYPE!>bar4<!> } else { ::<!CANNOT_INFER_PARAMETER_TYPE!>foo4<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll15(flag: Boolean) {
    val inv = if (flag) { ::<!UNRESOLVED_REFERENCE!>bar5<!> } else { ::<!UNRESOLVED_REFERENCE!>foo5<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll16(flag: Boolean) {
    val inv = if (flag) { ::Foo6 } else { ::Foo6 }
    inv()
}

fun poll17(flag: Boolean) {
    val inv = if (flag) { foo7() } else { ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!> }
    inv
}

fun poll2(flag: Boolean) {
    val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar<!> else -> ::<!UNRESOLVED_REFERENCE!>foo<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll21(flag: Boolean) {
    val inv = when (flag) { true -> ::bar2 else -> ::foo2 }
    inv()
}

fun poll22(flag: Boolean) {
    val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar3<!> else -> ::<!UNRESOLVED_REFERENCE!>foo3<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll23(flag: Boolean) {
    val inv = when (flag) { true -> ::<!CANNOT_INFER_PARAMETER_TYPE!>bar4<!> else -> ::<!CANNOT_INFER_PARAMETER_TYPE!>foo4<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll24(flag: Boolean) {
    val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar5<!> else -> ::<!UNRESOLVED_REFERENCE!>foo5<!> }
    inv
}

fun poll25(flag: Boolean) {
    val inv = when (flag) { true -> ::Foo6 else -> ::Foo6 }
    inv
}

fun poll26(flag: Boolean) {
    val inv = when (flag) { true -> ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!> false -> foo7() <!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!> }
    inv
}

fun poll3(flag: Boolean) {
    val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar<!> false -> ::<!UNRESOLVED_REFERENCE!>foo<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll31(flag: Boolean) {
    val inv = when (flag) { true -> ::bar2 false -> ::foo2 }
    inv()
}

fun poll32(flag: Boolean) {
    val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar3<!> false -> ::<!UNRESOLVED_REFERENCE!>foo3<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll33(flag: Boolean) {
    val inv = when (flag) { true -> ::<!CANNOT_INFER_PARAMETER_TYPE!>bar4<!> false -> ::<!CANNOT_INFER_PARAMETER_TYPE!>foo4<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll34(flag: Boolean) {
    val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar5<!> false -> ::<!UNRESOLVED_REFERENCE!>foo5<!> }
    inv
}

fun poll35(flag: Boolean) {
    val inv = when (flag) { true -> ::Foo6 false -> ::Foo6 }
    inv
}

fun poll36(flag: Boolean) {
    val inv = when (flag) { true -> ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!> false -> foo7() }
    inv
}

fun poll4() {
    val inv = try { ::<!UNRESOLVED_REFERENCE!>bar<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll41() {
    val inv = try { ::bar2 } finally { ::foo2 }
    inv()
}

fun poll42() {
    val inv = try { ::<!UNRESOLVED_REFERENCE!>bar3<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll43() {
    val inv = try { ::<!CANNOT_INFER_PARAMETER_TYPE!>bar4<!> } finally { ::<!CANNOT_INFER_PARAMETER_TYPE!>foo4<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll44() {
    val inv = try { ::<!UNRESOLVED_REFERENCE!>bar5<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo5<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll45() {
    val inv = try { ::Foo6 } finally { ::Foo6 }
    inv()
}

fun poll46() {
    val inv = try { foo7() } finally { ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!> }
    inv
}

fun poll5() {
    val inv = try { ::<!UNRESOLVED_REFERENCE!>bar<!> } catch (e: Exception) { ::<!UNRESOLVED_REFERENCE!>foo<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll51() {
    val inv = try { ::bar2 } catch (e: Exception) { ::foo2 } finally { ::foo2 }
    inv()
}

fun poll52() {
    val inv = try { ::<!UNRESOLVED_REFERENCE!>bar3<!> } catch (e: Exception) { ::<!UNRESOLVED_REFERENCE!>foo3<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll53() {
    val inv = try { ::<!CANNOT_INFER_PARAMETER_TYPE!>bar4<!> } catch (e: Exception) { ::<!CANNOT_INFER_PARAMETER_TYPE!>foo4<!> } finally { ::<!CANNOT_INFER_PARAMETER_TYPE!>foo4<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll54() {
    val inv = try { ::<!UNRESOLVED_REFERENCE!>bar5<!> } catch (e: Exception) { ::<!UNRESOLVED_REFERENCE!>foo5<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo5<!> }
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll55() {
    val inv = try { ::Foo6 } catch (e: Exception) { ::Foo6 } finally { ::Foo6 }
    inv()
}

fun poll56() {
    val inv = try { ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!> } catch (e: Exception) { foo7() } finally { foo7() }
    inv
}

fun poll6() {
    val inv = ::<!UNRESOLVED_REFERENCE!>bar<!>
    inv
}

fun poll61() {
    val inv = ::bar2
    inv
}

fun poll62() {
    val inv = ::<!UNRESOLVED_REFERENCE!>bar3<!>
    inv
}

fun poll63() {
    val inv = ::<!CANNOT_INFER_PARAMETER_TYPE!>bar4<!>
    inv
}

fun poll64() {
    val inv = ::<!UNRESOLVED_REFERENCE!>bar5<!>
    inv
}

fun poll65() {
    val inv = ::Foo6
    inv
}

fun poll66() {
    val inv = ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!>
    inv
}

fun poll7() {
    val inv = ::<!UNRESOLVED_REFERENCE!>bar<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll71() {
    val inv = ::bar2<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
    inv()
}

fun poll72() {
    val inv = ::<!UNRESOLVED_REFERENCE!>bar3<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll73() {
    val inv = ::<!CANNOT_INFER_PARAMETER_TYPE!>bar4<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
    inv
}

fun poll74() {
    val inv = ::<!UNRESOLVED_REFERENCE!>bar5<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
    inv
}

fun poll75() {
    val inv = ::Foo6<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
    inv
}

fun poll76() {
    val inv = ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
    inv
}

fun poll8() {
    val inv = ::<!UNRESOLVED_REFERENCE!>bar<!> in <!CANNOT_INFER_PARAMETER_TYPE!>setOf<!>(::<!UNRESOLVED_REFERENCE!>foo<!>)
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll81() {
    val inv = ::bar2 <!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>in<!> setOf(::foo2)
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll82() {
    val inv = ::<!UNRESOLVED_REFERENCE!>bar3<!> in <!CANNOT_INFER_PARAMETER_TYPE!>setOf<!>(::<!UNRESOLVED_REFERENCE!>foo3<!>)
    <!UNRESOLVED_REFERENCE!>inv<!>()
}

fun poll83() {
    val inv = ::<!CANNOT_INFER_PARAMETER_TYPE!>bar4<!> in <!CANNOT_INFER_PARAMETER_TYPE!>setOf<!>(::<!CANNOT_INFER_PARAMETER_TYPE!>foo4<!>)
    inv
}

fun poll84() {
    val inv = ::<!UNRESOLVED_REFERENCE!>bar5<!> in <!CANNOT_INFER_PARAMETER_TYPE!>setOf<!>(::<!UNRESOLVED_REFERENCE!>foo5<!>)
    inv
}

fun poll85() {
    val inv = ::Foo6 in setOf(::Foo6)
    inv
}

fun poll86() {
    val inv = ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!> in <!CANNOT_INFER_PARAMETER_TYPE!>setOf<!>(::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!>)
    inv
}

fun poll87() {
    val inv = ::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!> <!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>in<!> setOf(foo7())
    inv
}

fun poll88() {
    val inv = foo7() in <!CANNOT_INFER_PARAMETER_TYPE!>setOf<!>(::<!CANNOT_INFER_PARAMETER_TYPE!>Foo7<!>)
    inv
}

/* GENERATED_FIR_TAGS: asExpression, callableReference, checkNotNullCall, classDeclaration, equalityExpression,
funWithExtensionReceiver, functionDeclaration, ifExpression, integerLiteral, intersectionType, localProperty,
nullableType, propertyDeclaration, smartcast, tryExpression, typeParameter, whenExpression, whenWithSubject */
