[LC] Fix invalid nullability for properties
Fixed #KT-46097 and #KT-41671
This commit is contained in:
@@ -346,13 +346,14 @@ open class KtLightNullabilityAnnotation<D : KtLightElement<*, PsiModifierListOwn
|
|||||||
annotatedElement.bodyExpression?.let { it.getType(it.analyze()) }?.let { return it }
|
annotatedElement.bodyExpression?.let { it.getType(it.analyze()) }?.let { return it }
|
||||||
}
|
}
|
||||||
if (annotatedElement is KtProperty) {
|
if (annotatedElement is KtProperty) {
|
||||||
annotatedElement.initializer?.let { it.getType(it.analyze()) }?.let { return it }
|
(annotatedElement.initializer ?: annotatedElement.getter?.initializer)
|
||||||
|
?.let { it.getType(it.analyze()) }?.let { return it }
|
||||||
annotatedElement.delegateExpression?.let { it.getType(it.analyze())?.arguments?.firstOrNull()?.type }?.let { return it }
|
annotatedElement.delegateExpression?.let { it.getType(it.analyze())?.arguments?.firstOrNull()?.type }?.let { return it }
|
||||||
}
|
}
|
||||||
|
|
||||||
return annotatedElement.getParentOfType<KtProperty>(false)?.let {
|
return annotatedElement.getParentOfType<KtProperty>(false)?.let {
|
||||||
it.typeReference?.getType()
|
it.typeReference?.getType()
|
||||||
?: it.initializer
|
?: (it.initializer ?: it.getter?.initializer)
|
||||||
?.let { initializer -> initializer.getType(initializer.analyze()) }
|
?.let { initializer -> initializer.getType(initializer.analyze()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ fun fastCheckIsNullabilityApplied(lightElement: KtLightElement<*, PsiModifierLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
val parent = annotatedElement.parent.parent
|
val parent = annotatedElement.parent.parent
|
||||||
if (parent is KtModifierListOwner && parent.isPrivate()) return false
|
if (parent is KtModifierListOwner && parent !is KtPrimaryConstructor && parent.isPrivate()) return false
|
||||||
|
|
||||||
if (parent is KtPropertyAccessor) {
|
if (parent is KtPropertyAccessor) {
|
||||||
val propertyOfAccessor = parent.parent
|
val propertyOfAccessor = parent.parent
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
class TestConstructor private constructor(p: Int = 1)
|
class TestConstructor private constructor(p: Int = 1)
|
||||||
class A(vararg a: Int, f: () -> Unit) {}
|
class A(vararg a: Int, f: () -> Unit) {}
|
||||||
|
|
||||||
@@ -15,3 +14,7 @@ class Outer {
|
|||||||
sealed class A(val x: String? = null) {
|
sealed class A(val x: String? = null) {
|
||||||
class C : A()
|
class C : A()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ClassWithPrivateCtor private constructor(
|
||||||
|
public val property: Set<Int>
|
||||||
|
)
|
||||||
@@ -101,3 +101,9 @@ interface A {
|
|||||||
public get
|
public get
|
||||||
internal set
|
internal set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
val foo get() = getMeNonNullFoo()
|
||||||
|
val foo2: Foo get() = getMeNonNullFoo()
|
||||||
|
fun getMeNonNullFoo() : Foo = Foo()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user