New J2K: correctly remove redundant property type in a case of nullable initializer

This commit is contained in:
Ilya Kirillov
2019-05-20 01:15:28 +03:00
parent 8f5c690cdd
commit 54432448e3
@@ -499,13 +499,11 @@ object NewJ2KPostProcessingRegistrar {
if (needLocalVariablesTypes && element.isLocal) return false
if (needFieldTypes && element.isMember) return false
val initializer = element.initializer ?: return false
val withoutExpectedType = initializer.analyzeInContext(initializer.getResolutionScope())
val withoutExpectedType =
initializer.analyzeInContext(initializer.getResolutionScope()).getType(initializer) ?: return false
val descriptor = element.resolveToDescriptorIfAny() as? CallableDescriptor ?: return false
return when (withoutExpectedType.getType(initializer)) {
descriptor.returnType -> true
descriptor.returnType?.makeNotNullable() -> !element.isVar
else -> false
}
return if (element.isVar) withoutExpectedType == descriptor.returnType
else withoutExpectedType.makeNotNullable() == descriptor.returnType?.makeNotNullable()
}
if (!check(element)) {