From c31b5beb9e5dc957b6702312fc9e45c5f4c1dbe3 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 22 Sep 2017 18:28:20 +0300 Subject: [PATCH] Remove redundant check for a variable being initialized after write It's anyway is obvious for write instruction, while effectively after optimizations we treat val with syntactic initializer uninitialized until their immediate initiazer --- .../jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt | 4 +--- .../testData/diagnostics/tests/controlFlowAnalysis/kt897.kt | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt index 1677ba47563..94af80a4eb0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt @@ -500,9 +500,7 @@ class ControlFlowInformationProvider private constructor( // is not declared enterInitState?.isDeclared != true && exitInitState?.isDeclared != true && // wasn't initialized before current instruction - enterInitState?.mayBeInitialized() != true && - // became initialized after current instruction - exitInitState?.mayBeInitialized() == true + enterInitState?.mayBeInitialized() != true private fun checkInitializationForCustomSetter(ctxt: VariableInitContext, expression: KtExpression): Boolean { val variableDescriptor = ctxt.variableDescriptor diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.kt index ee10f766706..eb279e36d50 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.kt @@ -4,7 +4,7 @@ package kt897 class A() { init { - i = 11 + i = 11 } val i : Int? = null // must be an error