The good old "Condition ... is always false" Warning

已回答

I know. Not a new topic at all. However, I am not after advise how to suppress the warning. But I would like to understand why it is occurring in the first place.

fun Float.someFunction() {
    if(this > 0f) {"doSomething"}
}

This gives the well known warning 'Condition 'this > 0f' is always false '. This is in my - possibly naive - understanding obviously wrong.

What happens under hood that leads the compiler to this conclusion? Is there some simple way to explain it? 

 

0
You're right - this warning shouldn't appear in your example. I tested the code on both Kotlin 1.x and Kotlin 2.x, and it doesn't reproduce the 'Condition 'this > 0f' is always false' warning.

It's possible that your IDE is working with some outdated or corrupted cache, which might confuse the analysis engine. I suggest trying this:
File → Cache Recovery → Repair IDE

If the warning is still there, register ian ssue in Kthe TIJ project: https://youtrack.jetbrains.com/issues
0
You're right - this warning shouldn't appear in your example. I tested the code on both Kotlin 1.x and Kotlin 2.x, and it doesn't reproduce the 'Condition 'this > 0f' is always false' warning.

It's possible that your IDE is working with some outdated or corrupted cache, which might confuse the analysis engine. I suggest trying this:
File → Cache Recovery → Repair IDE

If the warning is still there, register ian ssue in Kthe TIJ project: https://youtrack.jetbrains.com/issues
0

I did that and it did not help. 

I managed to enter an issue here: https://youtrack.jetbrains.com/newIssue?draftId=25-6761136 .

However, it is in state “DRAFT”. I fail to see how I can actually submit it. The “Create” Button is always grayed out. Apparently some inpute field hasn't been filled in or something.

 

0
Hi, sorry for the delay. The Create button stays disabled if the Summary field is empty. If it still doesn’t work for you, just paste the body text here and I’ll create the issue myself and send you the link.
0

OMG! I took the leading “Summary” text in the form as title and the rest of the form IS the summary. Didn't realize that it is an input field. My bad.

I have submitted the issue now.

0

And we can close this thread now. The problem went away after upgrading to the 2025.2 version.

See my last comment in https://youtrack.jetbrains.com/issue/KTIJ-35329/Erroneous-Condition-...-is-always-false-Warning 

0

请先登录再写评论。