mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin-dfa] Box/unbox result of try/catch (KTIJ-29010)
GitOrigin-RevId: 40a12cce011a186e1cc730df757d5e5db2ecbef1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
44bd206e34
commit
fd50f306c9
+4
-1
@@ -1005,7 +1005,8 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
val finallyDescriptor = if (finallyBlock != null) EnterFinallyTrap(finallyBlock, finallyStart) else null
|
||||
finallyDescriptor?.let { trapTracker.pushTrap(it) }
|
||||
|
||||
val tempVar = flow.createTempVariable(DfType.TOP)
|
||||
val kotlinType = statement.getKotlinType()
|
||||
val tempVar = flow.createTempVariable(kotlinType.toDfType())
|
||||
val sections = statement.catchClauses
|
||||
val clauses = LinkedHashMap<CatchClauseDescriptor, DeferredOffset>()
|
||||
if (sections.isNotEmpty()) {
|
||||
@@ -1019,6 +1020,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
}
|
||||
|
||||
processExpression(tryBlock)
|
||||
addImplicitConversion(tryBlock, kotlinType)
|
||||
addInstruction(JvmAssignmentInstruction(null, tempVar))
|
||||
|
||||
val gotoEnd = createTransfer(statement, tryBlock, tempVar, true)
|
||||
@@ -1035,6 +1037,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
setOffset(offset)
|
||||
val catchBlock = section.catchBody
|
||||
processExpression(catchBlock)
|
||||
addImplicitConversion(catchBlock, kotlinType)
|
||||
addInstruction(JvmAssignmentInstruction(null, tempVar))
|
||||
controlTransfer(gotoEnd, singleFinally)
|
||||
}
|
||||
|
||||
+1
@@ -92,6 +92,7 @@ class K2DataFlowInspectionTest : AbstractK2InspectionTest() {
|
||||
fun testSuppressionsK2() = doTest()
|
||||
fun testTopLevelDeclaration() = doTest()
|
||||
fun testTryCatch() = doTest()
|
||||
fun testTryCatchReturnValue() = doTest()
|
||||
fun testTryCatchInsideFinally() = doTest()
|
||||
fun testTryFinally() = doTest()
|
||||
fun testTypeCastK2() = doTest()
|
||||
|
||||
+4
-1
@@ -208,7 +208,8 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
val finallyDescriptor = if (finallyBlock != null) EnterFinallyTrap(finallyBlock, finallyStart) else null
|
||||
finallyDescriptor?.let { trapTracker.pushTrap(it) }
|
||||
|
||||
val tempVar = flow.createTempVariable(DfType.TOP)
|
||||
val kotlinType = statement.getKotlinType()
|
||||
val tempVar = flow.createTempVariable(kotlinType.toDfType())
|
||||
val sections = statement.catchClauses
|
||||
val clauses = LinkedHashMap<CatchClauseDescriptor, DeferredOffset>()
|
||||
if (sections.isNotEmpty()) {
|
||||
@@ -222,6 +223,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
}
|
||||
|
||||
processExpression(tryBlock)
|
||||
addImplicitConversion(tryBlock, kotlinType)
|
||||
addInstruction(JvmAssignmentInstruction(null, tempVar))
|
||||
|
||||
val gotoEnd = createTransfer(statement, tryBlock, tempVar, true)
|
||||
@@ -238,6 +240,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
setOffset(offset)
|
||||
val catchBlock = section.catchBody
|
||||
processExpression(catchBlock)
|
||||
addImplicitConversion(catchBlock, kotlinType)
|
||||
addInstruction(JvmAssignmentInstruction(null, tempVar))
|
||||
controlTransfer(gotoEnd, singleFinally)
|
||||
}
|
||||
|
||||
+1
@@ -93,6 +93,7 @@ class KtDataFlowInspectionTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
fun testSuppressions() = doTest()
|
||||
fun testTopLevelDeclaration() = doTest()
|
||||
fun testTryCatch() = doTest()
|
||||
fun testTryCatchReturnValue() = doTest()
|
||||
fun testTryCatchInsideFinally() = doTest()
|
||||
fun testTryFinally() = doTest()
|
||||
fun testTypeCast() = doTest()
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// WITH_STDLIB
|
||||
fun main() {
|
||||
if (<warning descr="Condition '1 == try { 1 } catch (e: Exception) { null }' is always true">1 == try { 1 } catch (e: Exception) { null }</warning>) {}
|
||||
}
|
||||
Reference in New Issue
Block a user