mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-04 00:21:30 +00:00
Simplify boolean == true / false is no longer applicable on flexible boolean #KT-15087 Fixed
This commit is contained in:
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||
import org.jetbrains.kotlin.types.isFlexible
|
||||
|
||||
class SimplifyBooleanWithConstantsInspection : IntentionBasedInspection<KtBinaryExpression>(SimplifyBooleanWithConstantsIntention::class)
|
||||
|
||||
@@ -136,7 +137,7 @@ class SimplifyBooleanWithConstantsIntention : SelfTargetingOffsetIndependentInte
|
||||
|
||||
private fun KtExpression?.hasBooleanType(): Boolean {
|
||||
val type = this?.getType(this.analyze()) ?: return false
|
||||
return KotlinBuiltIns.isBoolean(type)
|
||||
return KotlinBuiltIns.isBoolean(type) && !type.isFlexible()
|
||||
}
|
||||
|
||||
private fun KtExpression.canBeReducedToBooleanConstant(constant: Boolean? = null): Boolean {
|
||||
|
||||
5
idea/testData/intentions/simplifyBooleanWithConstants/flexibleBoolean.1.java
vendored
Normal file
5
idea/testData/intentions/simplifyBooleanWithConstants/flexibleBoolean.1.java
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
class FromJava {
|
||||
static Boolean foo() {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
4
idea/testData/intentions/simplifyBooleanWithConstants/flexibleBoolean.kt
vendored
Normal file
4
idea/testData/intentions/simplifyBooleanWithConstants/flexibleBoolean.kt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun bar() = <caret>FromJava.foo() == true
|
||||
@@ -12939,6 +12939,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("flexibleBoolean.kt")
|
||||
public void testFlexibleBoolean() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyBooleanWithConstants/flexibleBoolean.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inapplicableNoConstants.kt")
|
||||
public void testInapplicableNoConstants() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyBooleanWithConstants/inapplicableNoConstants.kt");
|
||||
|
||||
Reference in New Issue
Block a user