Hi! I am having a problem with chosing an extensio...
# announcements
n
Hi! I am having a problem with chosing an extension function in a
when
block. The type does not get inferred... here is a little reproducible gist: https://gist.github.com/noncom/ea3e57e676a799efe2943a34b06f2986
a
Try
Int::one
instead of
{one()}
n
@Andreas Sinz that works! however, I think I've failed to capture the whole essense of the case with my test gist... I have changed the gist, please look again. In my real case, every extension function also takes some arguments at the decision site
the
::
way does not allow for arguments afaik?
a
in your updated gist,
::
doesn't work
seems like the Type information doesn't make it through the when statement into the cases, so you need to use anonymous functions
0 -> fun Int.() = one(10)
or the type inference works the other way, from the result of the case back to the result of the when
@noncom oh, i found out whats happening here. You can surround a case with
{ }
Copy code
case 0 -> {
    println("Case 0")
    
    { one(10) }
}
So in your example, kotlin thinks that
{ }
denotes the case-block, NOT that its a lambda. If you use
0 -> { { one(10) } }
it works
n
@Andreas Sinz wow! thanks a bunch! it worked 🙂 ...and people blame lisp for parentheses...
😂 1