don't report autocast on left expression in equality

if it was checked for not-null beforehand
This commit is contained in:
Svetlana Isakova
2013-12-09 16:11:35 +04:00
parent 90535283ba
commit 4a26c9df04
3 changed files with 21 additions and 2 deletions
@@ -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();
@@ -0,0 +1,5 @@
fun test(a: Any?) {
if (a is String) {
a == ""
}
}
@@ -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");