Implementation of smart casts for public / protected immutable properties that are not open and used in the same module.

DataFlowValueFactory and its environment refactoring: containing declaration is added into factory functions
as an argument and used to determine identifier stability. A few minor fixes. #KT-5907 Fixed. #KT-4450 Fixed. #KT-4409 Fixed.

New tests for KT-4409, KT-4450, KT-5907 (public and protected value properties used from the same module or not,
open properties, variable properties, delegated properties, properties with non-default getter).
Public val test and KT-362 test changed accordingly.
This commit is contained in:
Mikhail Glukhikh
2015-03-24 17:03:01 +03:00
parent 0b27d9181a
commit 9c1551bca9
39 changed files with 502 additions and 116 deletions
@@ -188,7 +188,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
doCheckType(
expressionType,
c.expectedType,
DataFlowValueFactory.createDataFlowValue(expression, expressionType, c.trace.getBindingContext()),
DataFlowValueFactory.createDataFlowValue(expression, expressionType, c),
c.dataFlowInfo
) {
expectedMustNotBeNull,
@@ -202,7 +202,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
val baseExpression = expression.getBaseExpression()
val baseExpressionType = c.trace.get(BindingContext.EXPRESSION_TYPE, baseExpression) ?: return
doIfNotNull(
DataFlowValueFactory.createDataFlowValue(baseExpression, baseExpressionType, c.trace.getBindingContext()),
DataFlowValueFactory.createDataFlowValue(baseExpression, baseExpressionType, c),
c
) {
c.trace.report(Errors.UNNECESSARY_NOT_NULL_ASSERTION.on(expression.getOperationReference(), baseExpressionType))
@@ -214,7 +214,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
val baseExpression = expression.getLeft()
val baseExpressionType = c.trace.get(BindingContext.EXPRESSION_TYPE, baseExpression) ?: return
doIfNotNull(
DataFlowValueFactory.createDataFlowValue(baseExpression, baseExpressionType, c.trace.getBindingContext()),
DataFlowValueFactory.createDataFlowValue(baseExpression, baseExpressionType, c),
c
) {
c.trace.report(Errors.USELESS_ELVIS.on(expression.getOperationReference(), baseExpressionType))
@@ -226,7 +226,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
JetTokens.EXCLEQEQEQ -> {
if (expression.getLeft() != null && expression.getRight() != null) {
SenselessComparisonChecker.checkSenselessComparisonWithNull(
expression, expression.getLeft()!!, expression.getRight()!!, c.trace,
expression, expression.getLeft()!!, expression.getRight()!!, c,
{ c.trace.get(BindingContext.EXPRESSION_TYPE, it) },
{
value ->
@@ -253,7 +253,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
safeAccess: Boolean,
c: CallResolutionContext<*>
) {
val dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiverArgument, c.trace.getBindingContext())
val dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiverArgument, c)
if (!safeAccess) {
doCheckType(
receiverArgument.getType(),