In the following code, inspections warn about the ...
# announcements
h
In the following code, inspections warn about the redundant
->
in the
else
of the `when`:
Copy code
internal fun hue(a: Double, b: Double): (Double) -> Double {
    val d = b - a
    return when {
        d.isTruthy() -> linear(a, if (d > 180 || d < -180) d - 360.0 * Math.round(d / 360.0) else d)
        else -> { _ -> if(a.isNaN()) b else a } // Redundant lambda arrow
    }
}
Removing it changes the type from
(Double) -> Double
to
Double
. Is there a better approach?
k
Looks like a bug in the idea warning then.
e
Well, it is really redundant, because you don't really ignore one lambda parameter. But removing it in this particular case leads to turning this lambda into code block of
else
branch, obviously. But I think you may try and wrap it into
{{ ... }}
. I tend to agree with @karelpeeters that this is idea warning bug
h
Yeah I understand what the warning is saying. It'd be nice if the inspection realized it's there so that the
when
produces the correct type. Seems like there's no way to not have the IDE warn me about something:
_: Double
gives the same warning, using a name instead of
_
warns that the parameter is never used,
k
You can surpress them but that's ugly.
p
Putting the lambda in parentheses should also work but this is one of the cases where the warning code doesn't look at the meaning of the suggested alternative, and thus doesn't see that it is not equivalent. Suppressing the warning at method level is probably the best thing to do.
a
Thank you, this is definitely a false positive in the inspection. I have created an issue https://youtrack.jetbrains.com/issue/KT-28047.