mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin-dfa] Fix float/double comparison
GitOrigin-RevId: 68699ea37c4a033fbc047045ee58856657585ba0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
34565bcae9
commit
a07f99ad4a
+1
-1
@@ -6,7 +6,7 @@ import com.intellij.codeInspection.dataFlow.types.DfTypes;
|
||||
import com.intellij.codeInspection.dataFlow.value.VariableDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
abstract class JvmVariableDescriptor implements VariableDescriptor {
|
||||
public abstract class JvmVariableDescriptor implements VariableDescriptor {
|
||||
@Override
|
||||
public boolean alwaysEqualsToItself(@NotNull DfType type) {
|
||||
return !type.isSuperType(DfTypes.FLOAT_NAN) &&
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
public class DoubleNaN {
|
||||
void test(double x, double y) {
|
||||
if (x > y) {}
|
||||
else if (x == y) {}
|
||||
else if (x < y) {}
|
||||
else {
|
||||
// x or y is NaN
|
||||
}
|
||||
}
|
||||
|
||||
native double getSomeDouble();
|
||||
|
||||
void testComparison() {
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.kotlin.idea.inspections.dfa
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.jvm.descriptors.JvmVariableDescriptor
|
||||
import com.intellij.codeInspection.dataFlow.types.DfType
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaValueFactory
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaVariableValue
|
||||
import com.intellij.codeInspection.dataFlow.value.VariableDescriptor
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.jvm.annotations.VOLATILE_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class KtVariableDescriptor(val variable: KtCallableDeclaration) : VariableDescriptor {
|
||||
class KtVariableDescriptor(val variable: KtCallableDeclaration) : JvmVariableDescriptor() {
|
||||
val stable: Boolean = calculateStable()
|
||||
|
||||
private fun calculateStable(): Boolean {
|
||||
@@ -152,7 +152,7 @@ class KtVariableDescriptor(val variable: KtCallableDeclaration) : VariableDescri
|
||||
!target.isExtensionDeclaration()
|
||||
}
|
||||
}
|
||||
class KtItVariableDescriptor(val lambda: KtElement, val type: KotlinType): VariableDescriptor {
|
||||
class KtItVariableDescriptor(val lambda: KtElement, val type: KotlinType): JvmVariableDescriptor() {
|
||||
override fun getDfType(qualifier: DfaVariableValue?): DfType = type.toDfType(lambda)
|
||||
override fun isStable(): Boolean = true
|
||||
override fun equals(other: Any?): Boolean = other is KtItVariableDescriptor && other.lambda == lambda
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(x: Double, y: Double) {
|
||||
if (x > y) {}
|
||||
else if (x == y) {}
|
||||
else if (x < y) {}
|
||||
else {
|
||||
// x or y is NaN
|
||||
}
|
||||
}
|
||||
fun test1(x: Double) : Boolean = x > 5
|
||||
fun test2(x: Double) : Boolean = x > 5 && <warning descr="Condition is always true when reached">x > 4</warning>
|
||||
Reference in New Issue
Block a user