diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 92beb936815..8db1abdb655 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -867,7 +867,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { JetBinaryExpression expression, ExpressionTypingContext context, JetSimpleNameExpression operationSign, - JetExpression left, + final JetExpression left, final JetExpression right ) { DataFlowInfo dataFlowInfo = context.dataFlowInfo; @@ -892,7 +892,16 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { traceInterpretingRightAsNullableAny.commit(new TraceEntryFilter() { @Override public boolean accept(@Nullable WritableSlice slice, Object key) { - return !(key == right && (slice == EXPRESSION_TYPE || slice == PROCESSED)); + + // the type of the right expression isn't 'Any?' actually + if (key == right && (slice == EXPRESSION_TYPE || slice == PROCESSED)) return false; + + // a hack due to KT-678 + // without this line an autocast is reported on the receiver (if it was previously checked for not-null) + // with not-null check the resolution result changes from 'fun Any?.equals' to 'equals' member + if (key == left && slice == AUTOCAST) return false; + + return true; } }, true); dataFlowInfo = facade.getTypeInfo(right, contextWithDataFlow).getDataFlowInfo(); diff --git a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/equalityUnderNotNullCheck.kt b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/equalityUnderNotNullCheck.kt new file mode 100644 index 00000000000..47dc3d1626c --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/equalityUnderNotNullCheck.kt @@ -0,0 +1,5 @@ +fun test(a: Any?) { + if (a is String) { + a == "" + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 570f36476d9..b9b09e24b29 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -4577,6 +4577,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/AssertNotNull.kt"); } + @TestMetadata("equalityUnderNotNullCheck.kt") + public void testEqualityUnderNotNullCheck() throws Exception { + doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/equalityUnderNotNullCheck.kt"); + } + @TestMetadata("funcLiteralArgsInsideAmbiguity.kt") public void testFuncLiteralArgsInsideAmbiguity() throws Exception { doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/funcLiteralArgsInsideAmbiguity.kt");