is the following possible w.r.t. the return statem...
# kotlin-native
k
is the following possible w.r.t. the return statement within the
let
block?
Copy code
NSURLSession.sharedSession.dataTaskWithRequest(
            NSURLRequest(NSURL(string = "<http://lsudflasfnlnf>")),
            requestBlock@ { data: NSData?, urlResponse: NSURLResponse?, error: NSError? ->
                error?.let {
                    return@requestBlock
                }
            }.freeze()
        ).resume()
interestingly, this causes an ICE as written: e: Compilation failed: No DECLARATION_TO_DESCRIPTOR for DOT_QUALIFIED_EXPRESSION: KtReturnExpression: return@requestBlock: KtLambdaExpression: ...
k
Can you provide a self-contained example? Perhaps the right imports are enough.
k
sure. just a little tweaking and the above can be self contained.
edited. that should do it.
k
Hmm, didn't see we were in /Native, sorry. But it does appear to be a native back-end bug, you should definitely put it on YouTrack if it isn't there already.
k
got it. so the code is correct as written?
k
I guess so. I can reproduce something of similar shape that the front-end + JVM/JVMIR be is happy with:
Copy code
object Test {
    fun foo(a: Int, action: (Int?) -> Unit) {
        action(2)
    }
}


fun main() {
    Test.foo(2, test@
        { a: Int? ->
            a?.let {
                println(it)
                return@test
            }
            println(4)
        })
}
๐Ÿป 1
Wait, looking closer at it -- what is .freeze() invoked on?
k
the lambda
k
Perfect, just double checking. It's an extention?
k
yes
it's part of K/N apis
k
Hah! Awesome ๐Ÿ˜„
I can reproduce the crash now!
It's an exception in Psi2IR, the link between front and back-ends.
So, scratch my previous comment that it should work. Possibly it should not, but the front-end doesn't correctly identify this,
My conclusion is a front-end bug:
Copy code
fun (() -> Nothing?).ext(): String = "OK"

fun box() =
    foo@{
        return@foo
    }.ext()
This throws the same error.
But should probably be rejected by the front-end. The IDE "infos" that the label is nonsensical.
k
hmm
so you believe it shouldn't work for K/N?
k
I am not sure of the specs for labels and lambdas; this works:
Copy code
fun (() -> Unit).ext(): String = "OK"


fun box() =
    foo@{
        return@foo
    }

fun main() {
    println(box().ext())
}
So it should probably work.
I'll file it on YouTrack ๐Ÿ™‚
k
awesome, thanks!
k
Sure thing! You can follow at https://youtrack.jetbrains.com/issue/KT-36217 ๐Ÿ™‚
๐Ÿป 1
Good news! My colleague worked out that label annotations bind very weakly in the parser, weaker than calls.
So, put parentheses around the labelled lambda, and it should work. Something like:
Copy code
NSURLSession.sharedSession.dataTaskWithRequest(
            NSURLRequest(NSURL(string = "<http://lsudflasfnlnf>")),
            (requestBlock@ { data: NSData?, urlResponse: NSURLResponse?, error: NSError? ->
                error?.let {
                    return@requestBlock
                }
            }).freeze()
        ).resume()
Try that for me, @Kris Wong?
k
๐Ÿ‘
k
Cool ๐Ÿ™‚
k
this works
k
Awesome! ๐Ÿ™‚
The CLI kotlinc rejects the old code in the front-end. Hence the ICE you saw in the IDE must be because the IDE uses only parts of the frontend.