Search in sources :

Example 1 with Nullability

use of org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability in project kotlin by JetBrains.

the class BasicExpressionTypingVisitor method checkNull.

private static void checkNull(@NotNull KtSimpleNameExpression expression, @NotNull ExpressionTypingContext context, @Nullable KotlinType type) {
    // Receivers are normally analyzed at resolve, with an exception of KT-10175
    if (type != null && !type.isError() && !isLValueOrUnsafeReceiver(expression)) {
        DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, type, context);
        Nullability nullability = context.dataFlowInfo.getStableNullability(dataFlowValue);
        if (!nullability.canBeNonNull() && nullability.canBeNull()) {
            if (isDangerousWithNull(expression, context)) {
                context.trace.report(ALWAYS_NULL.on(expression));
            } else {
                context.trace.record(SMARTCAST_NULL, expression);
            }
        }
    }
}
Also used : DataFlowValue(org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue) DataFlowValueFactory.createDataFlowValue(org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory.createDataFlowValue) Nullability(org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability)

Aggregations

DataFlowValue (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue)1 DataFlowValueFactory.createDataFlowValue (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory.createDataFlowValue)1 Nullability (org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability)1