Any reason why there is an inspection in one case ...
# intellij
k
Any reason why there is an inspection in one case but not the other?
Copy code
fun foo() {
    val a = 1
    val b = a.let { it }  // Highlighted with message "Redundant 'let' call could be removed 
    val c: Int
    a.let { c = it }      // No inspection! Could just be c = a.
}
p
a.let { c = it }
is an expression
c = a
is a statement the
let
is not redundant here as removing it would change it from expression to statement ?
a.let { it }
and
a
are both expressions with the same resulting value - hence redundant
k
Thanks, that's probably it. Now, I wonder why Kotlin makes such a big distinction between statements and expressions. Why aren't statements simply expressions of type Unit? (EDIT: I've just asked Gemini that question and got a fairly (not fully) convincing answer.)
c
Now, I wonder why Kotlin makes such a big distinction between statements and expressions. Why aren't statements simply expressions of type Unit?
Copy code
val a = val b = 3
With your proposal,
a
is
Unit
. Probably something you'd learn to avoid quite quickly, but still a bit weird to have in a language.
The inspection you're missing was possibly just forgotten, I think it's worth creating an issue