Enforce analysis inside top-level property initializer

Relates to #KT-36460
This commit is contained in:
Vladimir Dolzhenko
2020-02-11 12:56:56 +01:00
parent bf9e7ad09a
commit a0ed2c8640
5 changed files with 18 additions and 10 deletions
@@ -254,10 +254,7 @@ class KotlinCodeBlockModificationListener(
(element !is KtAnnotated || element.annotationEntries.isEmpty())
}
?.let { expression ->
val declaration = if (blockDeclaration.initializer != null)
blockDeclaration
else
// property could be initialized on a class level
val declaration =
KtPsiUtil.getTopmostParentOfTypes(blockDeclaration, KtClass::class.java) as? KtElement ?:
// ktFile to check top level property declarations
return null
@@ -1,4 +1,7 @@
// OUT_OF_CODE_BLOCK: FALSE
// TODO NOTE: [VD] Temporary workaround for KT-36460
// SKIP_ANALYZE_CHECK
// OUT_OF_CODE_BLOCK: TRUE
// ERROR: Unresolved reference: a
interface Some
@@ -1,6 +1,10 @@
// OUT_OF_CODE_BLOCK: FALSE
// TODO NOTE: [VD] Temporary workaround for KT-36460
// SKIP_ANALYZE_CHECK
// OUT_OF_CODE_BLOCK: TRUE
// ERROR: This variable must either have a type annotation or be initialized
// ERROR: Type mismatch: inferred type is Unit but Int? was expected
// ERROR: Type mismatch: inferred type is Unit but Int? was expected
val test: Int? = if (true) {
fun test() {
@@ -1,8 +1,10 @@
// OUT_OF_CODE_BLOCK: FALSE
// TODO NOTE: [VD] Temporary workaround for KT-36460
// SKIP_ANALYZE_CHECK
// OUT_OF_CODE_BLOCK: TRUE
// Problem with lazy initialization of nullable properties
// TODO: Investigate
// --ERROR: Unresolved reference: q
// ERROR: Unresolved reference: a
interface Some
val test: Some? = object: Some {
@@ -1,3 +1,5 @@
// OUT_OF_CODE_BLOCK: FALSE
// TODO NOTE: [VD] Temporary workaround for KT-36460
// SKIP_ANALYZE_CHECK
// OUT_OF_CODE_BLOCK: TRUE
val test: String = "<caret>"