https://kotlinlang.org logo
Title
k

karelpeeters

06/30/2018, 11:50 PM
That doesn't really matter if you're not using it as an expression, but the last statement in a lambda always is.
b

briedis

06/30/2018, 11:55 PM
What would be the best way here? Two separate lambdas?
if (isExisting) {
            context.database.use {
                update(RadarItem.TABLE, values, "id = ?", arrayOf(radar.id.toString()))
            }
        } else {
            context.database.use {
                insert(RadarItem.TABLE, RadarItem.C_TITLE, values)
            }
        }
Looks pretty bad though
k

karelpeeters

07/01/2018, 12:06 AM
Well there's no real problem, it's just a triggerhappy idea warning.
Maybe there's a way to surpress it?
b

briedis

07/01/2018, 7:36 AM
There is a suppression flag, but I ended up with casting the update value to long.
update(RadarItem.TABLE, values, "id = ?", arrayOf(radar.id.toString())).toLong()
I guess if the conditional's result is not used, maybe it should not throw a warning like this. But that's the IDE's problem.
k

karelpeeters

07/01/2018, 7:38 AM
Right, problem is that it is used: it's the return value of the lambda.
b

briedis

07/01/2018, 8:57 AM
but if the lambda result is not assigned to anything? (am I understanding correctly, that the lambda is the use{} block?)
k

karelpeeters

07/01/2018, 9:00 AM
Well of course we know it isn't used, but that would require the compiler to look into the
use
function and even further to the surrounding code, which it currently doesn't do.
👍 1