anyone who would know, why following code fails b...
# announcements
j
anyone who would know, why following code fails because of type inference ?
Copy code
private val working = listOf<Pair<String, (View) -> Unit>>(
        "FOCUS_DOWN" to { it -> it.requestFocus(View.FOCUS_DOWN) }
)

Type inference failed. Expected type mismatch: inferred type is Pair<String, () -> [ERROR : <ERROR FUNCTION RETURN TYPE>]> but Pair<String, (View) -> Unit> was expected

private val failing = listOf<Pair<String, (View) -> Unit>>(
    "FOCUS_DOWN" to { it.requestFocus(View.FOCUS_DOWN) }
)
Copy code
//following is fine
"FOCUS_DOWN" to { it -> it.requestFocus(View.FOCUS_DOWN)

//this one fails
"FOCUS_DOWN" to { it.requestFocus(View.FOCUS_DOWN) }
s
works for me actually, wonder if this is just an intellij bug
j
maybe kotlin compiler issue ? I have
Copy code
1.3.71
s
also using 1.3.71
j
hm, working in scratches, but not in android project
s
bizarre
z
Do you have New Type Inference enabled in the IDE?
s
I don’t think so
j
@Zach Klippenstein (he/him) [MOD] don't think so, how can I confirm that ?
doesn't seem to be related to IDE... just compiling it via gradle fails with same error
z
Open settings, search for Kotlin Compiler settings, there should be a checkbox to enable new type inference. But yea sounds like that's irrelevant, nvm.