Fix incremental analysis in case of property does not have initializer but could be initialized on a class level

#KT-35028 Fixed
This commit is contained in:
Vladimir Dolzhenko
2019-11-26 15:38:12 +01:00
parent c67222c176
commit 1c4c5520a2
2 changed files with 21 additions and 1 deletions
@@ -235,6 +235,14 @@ private class MergedDiagnostics(val diagnostics: Collection<Diagnostic>, overrid
override fun noSuppression() = this
}
/**
* Keep in mind: trace fallbacks to [resolveContext] (is used during resolve) that does not have any
* traces of earlier resolve for this [element]
*
* When trace turned into [BindingContext] it fallbacks to [parentContext]:
* It is expected that all slices specific to [element] (and its descendants) are stored in this binding context
* and for the rest elements it falls back to [parentContext].
*/
private class StackedCompositeBindingContextTrace(
val depth: Int, // depth of stack over original ktFile bindingContext
val element: KtElement,
@@ -238,7 +238,19 @@ class KotlinCodeBlockModificationListener(
// adding annotations to accessor is the same as change contract of property
(element !is KtAnnotated || element.annotationEntries.isEmpty())
}
?.let { return BlockModificationScopeElement(blockDeclaration, it) }
?.let { expression ->
val declaration = if (blockDeclaration.initializer != null)
blockDeclaration
else
KtPsiUtil.getTopmostParentOfTypes(
blockDeclaration,
// property could be initialized on a class level
KtClass::class.java,
// ktFile to check top level property declarations
KtFile::class.java
) as KtElement
return BlockModificationScopeElement(declaration, expression)
}
}
}
}